Alexander Obregon's Substack

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
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…

User's avatar

Continue reading this post for free, courtesy of Alexander Obregon.

Or purchase a paid subscription.
© 2026 Alexander Obregon · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture