Reported September 2026
Commvaultmath

Missing and Repeated Number

Reported by candidates from Commvault's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Commvault OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Commvault OA, reported in September 2026, is reaching for a hash set or sorting the array. Both work, and both break the O(1) space or no-mutation rule. The problem is simple on paper: nums holds values 1 through n, one value repeats, one is missing, and you return [repeated, missing]. The constraints are the real test. If you've got an invite and 48 hours, learn the math or XOR trick below and you're set. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you shouldn't need it for this one.

The problem

An unsorted integer array nums has length n and contains values from 1 through n. Exactly one value appears twice, exactly one value is missing, and every other value appears once.
Return an array containing the repeated value followed by the missing value. Solve the task in O(n) time and O(1) extra space without changing nums.

Function
findRepeatedAndMissing(nums: int[]) → int[]

Examples
Example 1
nums = [3,1,2,5,3]
return = [3,4]
The value 3 occurs twice and 4 is absent.
Example 2
nums = [1,1]
return = [1,2]
The repeated value is 1 and the missing value is 2.
Example 3
nums = [2,3,2,4]
return = [2,1]
The missing value can be smaller than the repeated value.

Constraints
2 <= n <= 200000.
1 <= nums[i] <= n.
Exactly one value occurs twice and exactly one value is absent.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is algebra. Let S be the sum of nums minus n(n+1)/2. That equals repeated minus missing, call it d. Let Q be the sum of squares of nums minus the sum of squares 1..n. That equals repeated^2 minus missing^2, so repeated plus missing is Q/d. Solve the two equations and you have both values in O(n) time and O(1) space. Use 64-bit integers, because with n up to 200000 the sum of squares reaches about 2.7e15 and overflows 32-bit. That's the common pitfall, along with the tempting trick of negating values in place, which mutates nums and is explicitly banned. An XOR approach also works: XOR everything with 1..n, split by the lowest set bit, then check which side value appears in nums. If you freeze during the live OA, StealthCoder can hand you the formula-based solution so you can type it out cleanly.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Missing and Repeated Number cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as set mismatch. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Commvault's OA.

Commvault reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Missing and Repeated Number FAQ

How hard is Missing and Repeated Number really?+

Easy to brute force, medium once you respect the constraints. A hash set or sort solves it in minutes, but O(1) extra space with no mutation forces the sum and sum-of-squares trick or XOR. If you've seen either idea once, it's a ten-minute problem.

What's the trick to solve it in O(1) space?+

Compare what you have to what you should have. The sum difference gives repeated minus missing. The squares difference gives repeated squared minus missing squared. Divide to get repeated plus missing, then solve the two linear equations. No extra memory needed beyond a few variables.

Why can't I just negate values in place?+

The Commvault problem says to solve it without changing nums. Index-marking by negation is the classic approach for similar problems, but it modifies the input. You could restore it afterward, yet the safest move is the math or XOR method that never touches the array.

What edge cases should I test?+

Test the smallest case, [1,1], which returns [1,2]. Test a missing value smaller than the repeated one, like [2,3,2,4]. Also test a large n for overflow. Use 64-bit integers for the sum of squares, since n can reach 200000.

How do I prepare for this in 48 hours?+

Write the sum and sum-of-squares solution from memory twice, then the XOR version once. Run the three given examples by hand. Spend the rest of your time on related array problems using counting and index logic, so the pattern feels familiar under pressure.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Commvault.

OA at Commvault?
Invisible during screen share
Get it