![]() |
VOOZH | about |
Given a Deque d containing non-negative integers.
Complete below functions depending type of query as mentioned and provided to you (indexing starts from 0):
1. eraseAt(x): this function should remove the element from specified position x in deque.
2. eraseInRange(start, end): this function should remove the elements in range start (inclusive), end (exclusive) specified in the argument of the function.
Note: If start is equal to end then simply return.
3. eraseAll(): remove all the elements from the deque.
Examples:
Input: d = [1 2 4 5 6], eraseAt(2)
Output: 1 2 5 6
Explanation: We remove element at position 2. The element at position 2 is 1 2 4 5 6. So, we remove 4 and get 1 2 5 6.Input: d = [1 2 3 4], eraseInRange(1, 3)
Output: 1 4
Explanation: Remember that end is exclusive. So the updated deque is 1 4.
1 4 5 6
eraseAt(deque<int>& d, int x): Time Complexity: O(n), Auxiliary Space: O(1)eraseInRange(deque<int>& d, int start, int end): Time Complexity: O(n), Auxiliary Space: O(1)eraseAll(deque<int>& d): Time Complexity: O(n), Auxiliary Space: O(1)