Missing Number CSES solution

Missing Number CSES solution
Missing Number CSES solution

You are given all numbers between 1,2,…,n1,2,…,n except one. Your task is to find the missing number.

Input

The first input line contains an integer n.

The second line contains n−1n−1 numbers. Each number is distinct and between 11 and n (inclusive).

Output

Print the missing number.

Constraints

  • 2≤n≤2⋅1052≤n≤2⋅105

Example

Input:
5
2 3 1 5

Output:
4

Code Solution

//Missing Number CSES solution codesagar.in

import java.util.*;
 
public class MissNum {
    
    
    public static void main(String args[]) {
     // Missing Number
    Scanner demo = new Scanner(System.in);
int count=0;
long n=demo.nextLong();
long []a=new long[(int)n];
while (demo.hasNextLong())
 
 {
 
// Scan an integer value
 
a[count]=demo.nextLong();
count++;
 
 }
 long x1=a[0];
 for(int i=1;i<n;i++){
    x1=x1 ^ a[i];
    }
  long x2=1;
for(int i=2;i<=n;i++){
    x2=x2 ^ i;
    }
    
System.out.println(x1^x2);
		
    }
}

//Missing Number CSES solution codesagar.in

Leave a Comment