FastPrepFind the Duplicate Number
Problems/Find the Duplicate Number

Find the Duplicate Number

Walmart Labs logoWalmart Labs● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a duplicate-number variant but omits the variant rule. This exercise uses the conventional read-only duplicate-number core; approximate source match: 70%.

You are given an integer array nums of length n + 1. Every value is in 1..n. Exactly one distinct value occurs more than once; it may occur more than twice. Return that value.

For this exercise, assume the conventional duplicate-number contract: do not modify the array, and aim for O(n) time and O(1) auxiliary space.

Function

findDuplicate(nums: int[]) → int

Examples

Example 1

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

Cycle entry differs from first value.

Example 2

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

Cycle-entry duplicate near the start.

Example 3

nums = [1,1]return = 1

Minimum n equals one.

Constraints

  • 1 <= n <= 1000.
  • nums.length = n + 1 and 1 <= nums[i] <= n.
  • Exactly one distinct value is repeated; all other values occur at most once.

More Walmart Labs Onsite Interview questions

  • Delayed Job SchedulerONSITE INTERVIEW · Seen Oct 2026
  • Product of Array Except SelfONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Run-Length Encoded Vector Dot ProductMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Longest Binary Window with at Most K OnesLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
See Walmart Labs hiring insights
Saved
class Solution {
    public int findDuplicate(int[] nums) {
        // Write your code here.
    }
}
Checking account…