FastPrep4Sum Index Quadruples
Problems/4Sum Index Quadruples

4Sum Index Quadruples

Airwallex logoAirwallex● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for all qualifying index quadruples without sorting the input and identifies a pair-sum map with result deduplication. Output ordering and safe bounds are specified for practice; the judged task matches at about 97%.

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 = 0return = [[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 = 8return = [[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.

More Airwallex problems

  • Named Async Task SchedulerOA · Seen Oct 2026
  • Paginated K-Way Unique MergePHONE SCREEN · Seen Sep 2026
  • Largest Rectangle in HistogramPHONE SCREEN · Seen Aug 2026
All Airwallex interview questionsSee Airwallex hiring insights
Saved
class Solution {
    public int[][] fourSumIndices(int[] nums, long target) {
        // Write your code here.
    }
}
Checking account…