Exit
  1. Learn
  2. Check
  3. Solve
  4. Reflect

Goal: Read the first and last values.

Open a box by its number

An array keeps values in a row of numbered boxes. The number of a box is its index, and it starts at 0. To read a box, write the array's name with the index in square brackets: nums[0] is the first value.

That's why reading any box is instant, however long the array is. The computer doesn't search: it goes straight to box 3, the way you'd walk straight to locker 3.

The first box is box 0: the second is box 1.
Any box, instantly: no searching needed.
Step through the indices
6
0
1
1
8
2
3
3
9
4
i

Box 0 holds 6, the first value. In code that's nums[0].

Move 1 of 4

The last box is one less than the length

The length is how many boxes there are. With 5 boxes numbered from 0, the numbers are 0, 1, 2, 3 and 4. So the last box is always the length minus one.

Asking for box 5 in a row of 5 is asking for a locker that isn't there. Depending on the language you'll get an error or a strange value, so it's worth getting this right early.

Last box: the length minus one.
Box number = length: is one past the end.
In code
marks = [72, 85, 64, 90, 58]
# the first box
top = marks[0]
# the last box: length minus one
bottom = marks[len(marks) - 1]