Sobes.tech
Junior — Senior

Removing duplicates without using extra memory

livecode

Task condition

The method removes all duplicate values from a list of integers without resorting to creating additional data structures. The function should return a new list in which each element appears only once, with memory usage limited to O(1).

Input data: [1, 4, 5, 4, 2, 1] Expected result: [1, 4, 5, 2]

class Solution {
    public List<Integer> removeDuplicates(List<Integer> numbers) {
        // TODO
    }
}