people
array in ascending order.i
at the start (lightest person) and j
at the end (heaviest person) of the array.boats
to count the number of boats used.i
is less than or equal to j
:
a. If people[i] + people[j]
is less than or equal to limit
, increment i
(since the lightest person is now on a boat).
b. Decrement j
(since the heaviest person is now on a boat).
c. Increment boats
(a new boat is used).boats
.