Reported September 2026
Airwallextwo pointers

4Sum Index Quadruples

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

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

Airwallex reported this one in September 2026, and it looks like a classic 4Sum until you read the second paragraph. Indices define the result, not values, so the dedup trick you memorized will quietly fail you. If you skip duplicates like the standard solution does, Example 2 returns one quadruple instead of five. It's a two-pointers and sorting shape with a twist, and the twist is the whole question. If you blank on the index bookkeeping during the live OA, StealthCoder is the invisible safety net that reads the problem and hands you a working approach.

The problem

Given an integer array nums and an integer target, return every index quadruple [i, j, k, l] such that i < j < k < l and nums[i] + nums[j] + nums[k] + nums[l] == target.
Indices, not values, define a result. Distinct index combinations must therefore be retained even when their values are equal. Do not reorder or mutate nums. Return the quadruples in lexicographic order.

Function
fourSumIndices(nums: int[], target: long) → int[][]

Examples
Example 1
nums = [1,0,-1,0,-2,2]
target = 0
return = [[0,1,2,3],[0,2,4,5],[1,3,4,5]]
Each listed increasing index tuple selects four values whose sum is zero. No other index tuple qualifies.
Example 2
nums = [2,2,2,2,2]
target = 8
return = [[0,1,2,3],[0,1,2,4],[0,1,3,4],[0,2,3,4],[1,2,3,4]]
All five ways to choose four different indices are retained even though every selected value is identical.

Constraints
0 <= nums.length <= 400.
-10^9 <= nums[i], target <= 10^9.
The number of returned quadruples is at most 100000.
Use 64-bit arithmetic for intermediate sums.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trap is the dedup logic. Standard 4Sum sorts values and skips equal neighbors. Here that's wrong, because equal values at different indices are distinct answers. Also, you can't reorder nums, so sort a copy of index pairs or work with original indices directly. A clean approach: loop i < j, then use a hash map from pair sum to a list of (k, l) pairs with k < l, only combining where k > j. Alternatively, sort indices by value, two-pointer, and expand runs of equal values to emit every index combination, then sort the final list lexicographically. With n up to 400 and output capped at 100000, O(n^2) pair work plus output size is fine. Use 64-bit sums, since four values near 10^9 overflow 32-bit. If it gets messy live, StealthCoder is your hedge for the indexing details.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill 4Sum Index Quadruples 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Airwallex reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

4Sum Index Quadruples FAQ

What's the trick in 4Sum Index Quadruples?+

Stop deduplicating by value. The problem wants every increasing index tuple, so equal values at different positions all count. Example 2 proves it: five 2s give five quadruples. Your code must enumerate index combinations, not skip repeated numbers like the classic 4Sum does.

Why does the standard 4Sum solution fail here?+

The classic version sorts and skips duplicate values to return unique value sets. This problem keeps duplicates by index. Skipping equal neighbors drops valid answers. You'd also lose original indices after sorting unless you carry them along, and the problem forbids mutating nums.

What complexity should I aim for?+

With n up to 400, an O(n^2) pair-sum map plus output-sensitive enumeration works. The output is capped at 100000 quadruples, so building results is bounded. A plain O(n^4) loop is 400^4, far too slow, so don't brute force it.

How do I return results in lexicographic order?+

If you iterate i, then j, then k, then l in increasing order, results come out sorted naturally. If you use a hash map or two pointers, collect the tuples and sort them at the end. Sorting 100000 small arrays is cheap.

Do I need to worry about overflow?+

Yes. Values reach 10^9 in magnitude, so four of them sum to 4*10^9, past 32-bit range. The target is also given as long. Use 64-bit integers for every intermediate sum, especially in languages like Java or C++ where int overflows silently.

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

OA at Airwallex?
Invisible during screen share
Get it