![]() |
VOOZH | about |
Given an array of integers, the task is to delete an element from the beginning of the array.
Examples:
Input: arr[] = [10, 20, 30, 40]
Output: [20, 30, 40]Input: arr[] = [20]
Output: []
We will use library methods like erase() in C++, remove() in Java, del in Python, removeAt() in C# and shift() in JavaScript.
Array before deletion 10 20 30 40 Array after deletion 20 30 40
Time Complexity: O(n)
Auxiliary Space: O(1)
The idea is to start from the second element and shift all the elements one position to the left. After shifting all the elements, reduce the array size by 1 to remove the extra element at the end.
Array before deletion 10 20 30 40 Array after deletion 20 30 40
Time Complexity: O(n)
Auxiliary Space: O(1)