3Sum Smaller
3Sum Smaller is a Medium Data Structures and Algorithms interview problem you can solve, run and submit on Thita.ai. It belongs to the Two Pointers pattern, in the Converging (Sorted Array Target Sum) subpattern.
Problem statement
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.
Topics and companies
Topics: Array, Two Pointers, Binary Search, Sorting.
Reported in interviews at IBM, Citadel.
How to practise 3Sum Smaller on Thita.ai
Starter code is provided in C#, C++, Go, Java, JavaScript and Python. Your solution runs against 5 test cases for this problem, with the AI coach available for a hint when you are stuck rather than a finished answer. The reference solution runs in O(n^2) time and O(1) space.
Open 3Sum Smaller in the code editor, or read the 3Sum Smaller editorial for a worked solution with its approach and complexity analysis.
Where 3Sum Smaller sits in the DSA pattern sheet
- Two Pointers pattern guide
- Converging (Sorted Array Target Sum) subpattern
- The full DSA patterns sheet
- All coding practice problems
Problems related to 3Sum Smaller
Other problems that use the same Converging (Sorted Array Target Sum) and Two Pointers techniques:
- Boats to Save People — Medium, same subpattern
- Container With Most Water — Medium, same subpattern
- 4Sum — Medium, same subpattern
- Squares of a Sorted Array — Easy, same subpattern
- 3Sum Closest — Medium, same subpattern
- 3Sum — Medium, same subpattern
Preparing your workspace
Progress is saved as you study.