Data Structures · Visualization

Remove at Index

Array

Removing from an array deletes the value at a chosen position and closes the gap it leaves behind, so the array stays contiguous with no holes. Time: O(n) worst case (removing near the start shifts almost everything). Space: O(1) extra space.

Big-O: Random access O(1); insert/delete in the middle O(n).

Remove at Index

Array

Removing from an array deletes the value at a chosen position and closes the gap it leaves behind, so the array stays contiguous with no holes. This is the mirror image of inserting: instead of shifting elements right to make room, you shift elements left to fill the empty spot.

How Remove at Index Works

  1. Locate the element at the target index to remove.
  2. Shift every element after that index one position to the left.
  3. Continue shifting until the last element has moved.
  4. Reduce the tracked length of the array by one.

Remove at Index Worked Example

Input: Remove the element at index 1 from [10, 20, 30, 40]

  1. Element at index 1 is 20 — it will be removed.
  2. Shift 30 left from index 2 to index 1: [10, 30, 30, 40]
  3. Shift 40 left from index 3 to index 2: [10, 30, 40, 40]
  4. Drop the last duplicate slot: [10, 30, 40]

Output: [10, 30, 40]

Try your own input
Remove at IndexO(n)
Shifts every element after the target index one slot to the left, closing the gap left behind.
10
0
20
idx 1 ▾
30
2
40
3
Active / shifting Result
Remove at Index
Press ▶ Run to watch it step by step.
Python · Arrays in Code
def remove_at(arr, index):
    removed = arr[index]
    for i in range(index, len(arr) - 1):
        arr[i] = arr[i + 1]   # shift left
    arr.pop()                 # drop the tail
    return removed

a = [10, 20, 30, 40]
remove_at(a, 1)               # removes 2
# example: remove at index at index 1 on [10, 20, 30, 40]
Input: Remove the element at index 1 from [10, 20, 30, 40]

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Remove at Index Time & Space Complexity

TimeO(n) worst case (removing near the start shifts almost everything)
SpaceO(1) extra space

When to Use Remove at Index

  • Deleting a completed task from a task list while keeping the rest in order
  • Removing a player who has left a game's turn order
  • Cleaning invalid entries out of a dataset before processing it

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.