Reading the last box of a huge array takes 1 step
Tap to start →
Java jumps straight to the box. O(1), like a locker number.
In an unsorted array you check one by one. O(n).
Adding at the front moves every value one seat right. O(n).
Swap the two ends and move inwards. No extra array.
Indexes start at 0. An array of 10 boxes ends at index 9.
Tap an answer. The full video explains why.
Free DSA in Java course. Subscribe to Compiled Canvas on YouTube.