FastPrepFind the Missing Number from 1 to n
Problems/Find the Missing Number from 1 to n

Find the Missing Number from 1 to n

GEP logoGEP● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the exact task of finding the missing value from 1 through n, and suggests sorting, hashing, summing, and XOR. It does not give limits or a function signature. This version returns the missing value directly. Our version is about 98% the same as the reported question.

You are given an integer array nums of length n - 1. The array contains distinct values chosen from every integer from 1 through n, inclusive, with exactly one value missing.

Return the missing value.

Function

findMissingNumber(nums: int[]) → int

Examples

Example 1

nums = [1,2,4,5]return = 3

Here n = 5. The only value from 1 through 5 absent from the array is 3.

Example 2

nums = [2,3,1]return = 4

The array length is 3, so n = 4; the missing value is 4.

Example 3

nums = []return = 1

An empty array represents n = 1, so 1 is missing.

Constraints

  • 1 <= n <= 100000.
  • nums.length = n - 1.
  • Every element of nums is a distinct integer in the inclusive range [1, n].
  • Exactly one integer from 1 through n is absent.

More GEP interview questions

  • Deduplicate a Sorted Array In PlacePHONE SCREEN · Seen Sep 2026
  • Reverse a Singly Linked ListONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Minimum Power-of-Two Removal OperationsIBM · OAIBM interview questions
  • Minimum Power-of-Two Removal OperationsVisa · OAVisa interview questions
  • Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
  • Bayesian Scenario ClassifierAmazon · ONSITE INTERVIEW
  • Count Valid Square PairsAuxoAI · OA
  • Picked Player Who LostSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Server InvestmentRippling · OARippling interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions
See GEP hiring insights
Saved
class Solution {
    public int findMissingNumber(int[] nums) {
        // Write your code here
    }
}
Checking account…