Alexander Obregon's Substack

Share this post

User's avatar
Alexander Obregon's Substack
LeetCode #18: 4Sum — Solved in Java
Java LeetCode Solutions

LeetCode #18: 4Sum — Solved in Java

Brute-Filtered Two-Pointer Scan and Early Exit Optimized with Long Bounds

Alexander Obregon's avatar
Alexander Obregon
Jul 28, 2025
∙ Paid
1

Share this post

User's avatar
Alexander Obregon's Substack
LeetCode #18: 4Sum — Solved in Java
Share
LeetCode Logo
Image Source

4Sum takes in an array of integers and asks you to find every set of four numbers that add up to a given target. You can use the same number more than once if it appears multiple times in the input, but each result has to be a unique combination. The order inside the array doesn’t matter, but repeated sets in the final list aren't allowed.

It…

Keep reading with a 7-day free trial

Subscribe to Alexander Obregon's Substack to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Alexander Obregon
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share