Problem · Array

Unique Target-Sum Pairs in a Sorted Doubly Linked List

Learn this problem
MediumArista Networks logoArista NetworksFULLTIMEPHONE SCREEN

Problem statement

A sorted array values lists the node values of a doubly linked list from head to tail. Return every distinct value pair whose sum equals target.

  • Use two different node positions for a pair.
  • Return each value pair only once, even when duplicate nodes allow it in several ways.
  • Within a pair, place the smaller value first. Order the result by the first value, then the second.

Function

findUniquePairs(values: int[], target: int) → int[][]

Examples

Example 1

values = [1,2,3,4,6,8]target = 10return = [[2,8],[4,6]]

Both distinct value pairs sum to 10.

Example 2

values = [1,1,2,2,3,3]target = 4return = [[1,3],[2,2]]

Repeated nodes do not create repeated value pairs.

Constraints

  • 0 <= values.length <= 10^5
  • -10^9 <= values[i] <= 10^9
  • values is sorted in nondecreasing order.
  • -10^9 <= target <= 10^9

More Arista Networks problems

drafts saved locally
public int[][] findUniquePairs(int[] values, int target) {
    // Write your solution here.
}
values[1,2,3,4,6,8]
target10
expected[[2,8],[4,6]]
checking account