Input: arr[] = {1, 2, 3, -1, -1, 4, 5, 6, -1, 0}
Output: 1 4 5 0
Explanation: The closest element to the 1st occurrence of -1 is 3 in {1, 2, 3, -1, -1, 4, 5, 6, -1, 0}. After removing -1 and 3 arr becomes {, 2, -1, 4, 5, 6, -1, 0}.
The closest element to the 1st occurrence of -1 is 2 in {1, 2, -1, 4, 5, 6, -1, 0}. After removing -1 and 2 arr becomes {1, 4, 5, 6, -1, 0}.
The closest element to the 1st occurrence of -1 is 6 in {1, 4, 5, 6, -1, 0}. After removing -1 and 6 arr becomes {1, 4, 5, 0}.
Input: arr[] = {-1, 0, 1, -1, 10}
Output: 0 10
Explanation: There is no element exist closest in right of first occurrence of -1 in {-1, 0, 1, -1, 10}. So we will only remove -1. After removing -1 arr becomes {0, 1, -1, 10}.
The closest element to the 1st occurrence of -1 is 1 in {0, 1, -1, 10}. After removing -1 and 1 arr becomes {0, 10}
Below is the implementation of the above approach.