βœ…Missing two(Contest)

Missing two easy asked in interviews by 1 company Time Limit: 2 sec Memory Limit: 128000 kB

Problem Statement :

Given an array in which all numbers except two are repeated once. (i. e. we have 2N+2 numbers and N numbers are occurring twice and remaining two have occurred once). Find those two numbers. Input First line of input contains a single integer N. The next line of input contains 2*N+2 space separated integers.

Constraints:- 1 < = N < = 10000 1 < = Arr[i] < = 100000000 Output Print the two elements separated by space (print the lower element first). Example Sample Input:- 2 1 3 4 1 5 3

Sample Output:- 4 5

Sample Input:- 3 1 2 3 5 4 3 2 1

Sample Output:- 4 5

link:https://my.newtonschool.co/playground/code/rzecnkw12qlk/

```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static void main (String[] args) {
        // Your code here
        Scanner sc = new Scanner(System.in);
        TreeMap<Integer,Integer>tm = new TreeMap<>();
        int n = sc.nextInt();
        int m = 2*n+2;
        int arr[] = new int[m];
        for(int i =0;i<m;i++){
            arr[i] = sc.nextInt();
            tm.put(arr[i],tm.getOrDefault(arr[i],0)+1);
        }
        for(int num:tm.keySet()){
            int k = tm.get(num);
            if(k==1){
            System.out.print(num+" ");
            }
        }
    }
}
```

Last updated