17.6 The Gasup Problem


#1

The solution seems wrong to me. The loop is from (1, num_cities), but it should be (1, num_cities + 1), as the last city in the list might have the minimum.


#2

Solution is right. Thats why it returns i. If we have found an ample city before, that would obviously be the answer. The only thing we aren’t sure is, if the last one is the ample city, when none of the previous ones are.
But the question is based on the assumption that an ample city exists, hence this works.