-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ef3021
commit c067247
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//Index of an extra element | ||
|
||
import java.util.*; | ||
|
||
class ExtraElement { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
int t = sc.nextInt(); | ||
|
||
while(t-- > 0) { | ||
int n = sc.nextInt(); | ||
int[] a = new int[n]; | ||
int[] b = new int[n - 1]; | ||
|
||
for(int i = 0; i < n; i++) | ||
a[i] = sc.nextInt(); | ||
|
||
for(int i = 0; i < n - 1; i++) | ||
b[i] = sc.nextInt(); | ||
|
||
Solution g = new Solution(); | ||
System.out.println(g.findExtra(n, a, b)); | ||
} | ||
} | ||
} | ||
|
||
class Solution { | ||
public int findExtra(int n, int arr1[], int arr2[]) { | ||
for(int i = 0; i < n - 1; i++) { | ||
if(arr1[i] != arr2[i]) { | ||
return i; | ||
} | ||
} | ||
|
||
return n - 1; | ||
} | ||
} |