Skip to content

Commit

Permalink
Create Index of an extra element
Browse files Browse the repository at this point in the history
  • Loading branch information
dishathakurata authored Jun 8, 2024
1 parent 1ef3021 commit c067247
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Index of an extra element
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;
}
}

0 comments on commit c067247

Please sign in to comment.