✅ EASIEST || 💯 BEATS || 🧑‍💻 JAVA || ⭐ TWO POINTERS
IntuitionThis problem builds on the "two-sum" and "three-sum" problems. To find four numbers that add up to a target value, we can try a sorted array and use tw
# Intuition

This problem builds on the "two-sum" and "three-sum" problems. To find four numbers that add up to a target value, we can try a sorted array and use two nested loops for the first two numbers. For the remaining pair, we can apply a two-pointer approach to find all unique quadruplets.
# Approach
Sort the Array: Sorting the array helps simplify handling duplicate values and allows the two-pointer technique.

Nested Loops: Use two nested loops to pick the first two numbers, nums[i] and nums[j]. Ensure these loops skip duplicates to avoid redundant calculations.

Two-Pointer Search: For the remaining two numbers, use two pointers (k starting right after j and l at the end of the array).

If the sum of nums[i], nums[j], nums[k], and nums[l] matches the target, add the quadruplet to the result.
Adjust pointers k and l to find other potential pairs, ensuring you skip over duplicates.
Result Storage: Store each unique quadruplet in a list and return this list of lists.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public List<List<Integer>> fourSum(int[] nums, int target) {
        List<List<Integer>> ans = new ArrayList<>();
        int len = nums.length;

        Arrays.sort(nums);

        for (int i = 0; i < len - 3; i++) {
            if (i > 0 && nums[i - 1] == nums[i]) 
                continue;

            for (int j = i + 1; j < len - 2; j++) {
                if (j > i + 1 && nums[j - 1] == nums[j])
                    continue;
                
                int k = j + 1;
                int l = len - 1;

                while (k < l) {
                    long sum = nums[i] + nums[j];
                    sum += nums[k] + nums[l];

                    if (sum == target) {
                        ans.add(Arrays.asList(nums[i], nums[j], nums[k], nums[l]));
                        k++;
                        l--;

                        while (k < l && nums[k - 1] == nums[k]) k++;
                        
                        while (k < l && nums[l + 1] == nums[l]) l--;
                    } else if (sum < target)
                        k++;
                    else 
                        l--;
                }
            }
        }

        return ans;
    }
}
```
['Array', 'Two Pointers', 'Sorting', 'Python', 'C++', 'Java']