4Sum

Photo by Yan Ming on Unsplash

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:

  • 0 <= a, b, c, d < n
  • a, b, c, and d are distinct.
  • nums[a] + nums[b] + nums[c] + nums[d] == target

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

--

--

--

Full Stack Programmer, love to solve problem’s during free time.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Parallel Processing using the Virtru Python SDK

Remote Agile vs. Scrum: The Spotify Model for Distributed Teams

Serverless Databases for Your Mobile or Web App

A complete guide to Oauth2 authentication

Microservices In Practice: Developing Instagram Clone —Graph Service

10 Things I learned from teaching a Full Stack Dev Bootcamp.

6MWD: Got my unit tests working

Getting started with AWS Lambda

AWS Lambda Summary

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jaydeep

Jaydeep

Full Stack Programmer, love to solve problem’s during free time.

More from Medium

Replace Words

This Pointer

Trapping Rainwater Problem: Three different approaches (brute to optimized)

raining gif

Google Interview Question — LeetCode 1423