4Sum
Medium · Array, Two Pointers, Sorting
Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:
You may return the answer in any order.
Example 1
Input: nums = [1,0,-1,0,-2,2], target = 0 Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
Example 2
Input: nums = [2,2,2,2,2], target = 8 Output: [[2,2,2,2]]
Constraints
- 1 <= nums.length <= 200
- -109 <= nums[i] <= 109
- -109 <= target <= 109
Starter code (python)
class Solution(object):
def fourSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[List[int]]
"""
Related problems
- Two Sum (Easy)
- Median of Two Sorted Arrays (Hard)
- Longest Palindromic Substring (Medium)
Previous: Letter Combinations of a Phone Number · Next: Remove Nth Node From End of List · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.