Reported September 2026
Capital Onehash table

Count One-Swap Number Pairs

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

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

The mistake that sinks most first attempts on this Capital One question, reported in September 2026, is checking every pair of numbers. With up to 10^4 elements that's 50 million comparisons, each with digit work on top. This is a hash-table counting problem in disguise. For each number, you generate every value reachable by one digit swap and look those values up in a frequency map. Leading zeroes make some swaps invalid. Duplicates count as pairs with no swap needed. If you blank on the details during the OA, StealthCoder is a quiet hedge running on your screen.

The problem

You are given an array of positive integers numbers. Count the index pairs (i, j) such that i < j and one number in the pair can be transformed into the other by swapping at most one pair of digit positions.
No swap is required when the two numbers are already equal. Each pair of indices is counted once, even when several different digit swaps produce the same value.
Use each number's ordinary decimal representation without leading zeroes. A swapped representation that begins with 0 is invalid, so valid transformed numbers have the same number of digits.
Return the number of qualifying index pairs.

Function
countOneSwapPairs(numbers: int[]) → int

Examples
Example 1
numbers = [1,23,156,1650,651,165,32]
return = 3
The qualifying pairs are 23 with 32, 156 with 651, and 156 with 165. Therefore, the result is 3.
Example 2
numbers = [123,321,123]
return = 3
The two copies of 123 form a qualifying pair without a swap. Each copy of 123 also pairs with 321 by swapping the first and last digits, for 3 pairs in total.

Constraints
1 &le; numbers.length &le; 10^4
1 &le; numbers[i] &le; 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: numbers have at most 10 digits, so each number has at most 45 digit-position swaps. Process the array left to right. For each number, build the set of distinct values reachable by one swap (include the number itself to cover equal values). Skip any swap that puts a 0 in front. Then add up the map count for each value in that set, and increment the map for the current number. Using a set per number is the whole point. Two different swaps can produce the same value, and the problem says each index pair counts once. Skipping the dedupe is the classic wrong answer. Example 2 checks it: [123,321,123] gives 3 only if the equal pair is counted once. Swapping two identical digits yields the number itself, which the set absorbs. Cost is about 10^4 times 45 operations, which is trivial. StealthCoder is there if the leading-zero or dedupe logic slips under pressure.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Count One-Swap Number Pairs 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Capital One reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count One-Swap Number Pairs FAQ

What's the trick in Count One-Swap Number Pairs?+

Don't compare pairs. For each number, generate all values reachable with at most one digit swap, then look them up in a frequency map of earlier numbers. At most 45 swaps per number makes this fast and avoids the quadratic scan.

Why does the answer overcount on my first try?+

Different swaps can produce the same value, and a pair of indices counts once. Put the generated values in a set before querying the map. Include the original number in that set so equal numbers count without a swap.

How do I handle leading zeroes?+

Work on the digit string. After swapping, if the first character is '0', discard that result. Valid transformed numbers keep the same digit count, so something like 1650 swapped into 0651 doesn't count.

How hard is this really for the Capital One OA?+

Medium. The idea is simple once you see the hash map, but the dedupe and leading-zero edge cases trip people up. Examples like [123,321,123] are worth tracing by hand before you submit.

How do I prepare in 48 hours?+

Write the solution once from scratch: frequency map, swap generator, set dedupe, zero check. Test it on both examples and a case with repeated digits like 110. Then practice a couple of other counting-with-hash-map problems for pattern recall.

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

OA at Capital One?
Invisible during screen share
Get it