All problems
0083MediumArrayTwo PointersSorting

Four-Card Bias Groups

Tracked in this browser only
Write code

Trains the technique from

LeetCode 184Sum

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A test bench stacks probe cards to cancel out a bias. You are given the integer array offsets, holding one signed bias figure per card in the tray, and an integer target.

Report every group of four cards whose bias figures total target. A group picks four distinct tray positions, so no card may be counted twice inside one group.

Two groups are the same group when they hold the same four figures with the same repeats, whichever tray positions supplied them; report such a group once only. Write the four figures of a group in non-decreasing order. The groups themselves may come back in any order. Return an empty list when no four cards total target.

Examples

Example 1

Input
offsets = [1, 5, 3, 6], target = 15
Output
[[1, 3, 5, 6]]

All four cards must be used, and 1 + 5 + 3 + 6 is 15, so the single group is the whole tray written in non-decreasing order.

Example 2

Input
offsets = [-6, -1, 0, 1, 6, 7], target = 0
Output
[[-6, -1, 0, 7], [-6, -1, 1, 6]]

Two distinct groups of figures reach 0 here; either ordering of the two groups is accepted.

Example 3

Input
offsets = [9, 9, 9], target = 27
Output
[]

Only three cards sit in the tray, so no group of four exists and the report is empty.

Constraints

  • 1 <= offsets.length <= 200
  • -10^9 <= offsets[i] <= 10^9
  • -10^9 <= target <= 10^9

The values you return may be in any order.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def bias_quartets(offsets: list[int], target: int) -> list[list[int]]:
Java
public List<List<Integer>> biasQuartets(int[] offsets, int target)
September 7
Apply