Interview Shuriken 53: Find the Missing Number


You are given an array containing ‘n’ distinct numbers taken from the range: [0, n]. Since the array contains only ‘n’ numbers and count of numbers from 0 to n is ‘n+1’, so, you have to find the missing number.

Example 1:

Input: [4, 0, 3, 1]
Output: 2

Example 2:

Input: [8, 3, 5, 2, 4, 6, 0, 1]
Output: 7
Input Format:
The first line of input contains an integer, that denotes the value of n. The following line contains n space separated integers, that denotes the value of array elements.
Constraints:
1 <= N <= 100000
0 <= A[i] <= N 
Time Limit: 0.5 seconds.
Output Format:
The first and only line of output contains the missing number, as described in the task.
Sample Input 1:
6
1 5 6 0 3 2
Sample Output 1:
4


## Read input as specified in the question.
## Print output as specified in the question.
n=int(input())
arr=list(map(int,input().split()))
res=set(arr)
[print(i,end=" ") for i in range(1,n+1) if i not in res]

Comments

Popular posts from this blog

MySQL Multi Source Master Slave Replication using GTID

Access and modify all the resources of our Wiki.js using WikiJS API

Setting Up PostgreSQL Logical Replication with Docker Compose