BackeasyArrays Cognizant

Find Missing Elements Solution

Problem Statement

Given an array of student numbers, find all absent student numbers. The absent student numbers are the numbers in the range [1, max(arr)] that are not present in arr.

Example 1
Input
[1, 2, 3, 4, 5]
Output
[6]

Explanation: Step-by-step: Given the input array [1, 2, 3, 4, 5], we first find the maximum number in the array, which is 5. Then, we generate a list of numbers from 1 to the maximum number (6). Finally, we return the list of numbers that are present in the range [1, 6] but not in the input array [1, 2, 3, 4, 5], which is [6].

Example 2
Input
[1, 2, 4, 5]
Output
[3, 6]

Explanation: Step-by-step: Given the input array [1, 2, 4, 5], we first find the maximum number in the array, which is 5. Then, we generate a list of numbers from 1 to the maximum number (6). Finally, we return the list of numbers that are present in the range [1, 6] but not in the input array [1, 2, 4, 5], which is [3, 6].

Constraints

  • 1 <= n <= 10^5
  • 1 <= arr[i] <= n
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free