Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Two pointers

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Two pointers

3Sum

intermediatelayer B4 · Two pointers5 tests

Given an integer array nums, return every unique triplet [a, b, c] of elements that sums to zero.

  • The three values must come from three different positions in the array
  • Two triplets are the same if they contain the same multiset of values, so [-1, 0, 1] and [0, 1, -1] count as one answer — report it once
  • The order of the triplets, and the order of values inside a triplet, does not matter
  • Return [] when there is no such triplet
  • Target complexity: O(n^2)

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen