![]() |
VOOZH | about |
Given an array of integers, the task is to delete an element from the end of the array.
Examples:
Input: arr[] = [10, 20, 30, 40]
Output: [10, 20, 30]Input: arr[] = [20]
Output: []
We will use library methods like pop_back() in C++, remove() in Java, pop() in Python and JavaScript and removeAt() in C#.
Array before deletion 10 20 30 40 Array after deletion 10 20 30
Time Complexity: O(1)
Auxiliary Space: O(1)
To delete an element from the end of an array, we can simply reduce the size of array by 1.
Array before deletion 10 20 30 40 Array after deletion 10 20 30
Time Complexity: O(1)
Auxiliary Space: O(1)