TCS OA-13 2024
Problem Description
Given an array of size N
containing integers in the range of[1, N+1]
, the task is to find the missing number from the first N
integers. The array is guaranteed to contain distinct integers, and exactly one integer from the range is missing.
Input Format
- The first line contains an integer N.
- The second line contains N space-separated integers.
Output Format
Print the missing number from the first N
integers.
Constraints
- 1 ≤ N < 10⁴
- 1 ≤ nums[i] ≤ 10⁴
Example
Sample Input:
4
[2, 3, 1, 5]
Sample Output:
4
Explanation:
The integers from 1 to 5 are [1, 2, 3, 4, 5].
The number 4 is missing from the provided array, which contains the numbers [2, 3, 1, 5].