Count shifts
Warm-up · Trace the algorithm · about 4 min
Delete the value at index 1 from [6, 2, 9, 4, 7, 1, 8]. Count how many values shift before each step plays.
Example 1
Input:
{"values":[6,2,9,4,7,1,8],"index":1}
Output:
[6,9,4,7,1,8]
Constraints
- The trace uses the input shown.
Learn the idea first: Arrays: indexing, traversal, insertion and deletion costs, a visual lesson.
More Arrays: indexing, traversal, insertion and deletion costs problems
- Insert at index Warm-up
- Reverse in place Warm-up
- Rotate by k Standard
- Delete at index by shifting Standard
- Move zeroes to the end in place Challenge