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

HyperVerge logoHyperVerge● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a HyperVerge intern onsite interview. The report names a well-known task. We chose the function signature, a fixed rule for the output, and the limits. 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.

Source note: Author-written prompt excerpt retained for source fidelity.

More HyperVerge interview questions

  • Reach a Given NumberOA · Seen Jul 2024

Similar questions at other companies

  • Bayesian Scenario ClassifierAmazon · ONSITE INTERVIEW
  • Find the Missing Number from 1 to nGEP · OA
  • 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
  • Confusing Bib NumbersVerily · ONSITE INTERVIEW
  • Plus OneDruva · ONSITE INTERVIEW
  • Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
See HyperVerge hiring insights
Saved
class Solution {
    public int findMissingNumber(int[] nums) {
        // Write your code here
    }
}
Checking account…