diff --git a/Index of an extra element b/Index of an extra element new file mode 100644 index 0000000..216eae6 --- /dev/null +++ b/Index of an extra element @@ -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; + } +}