Find Cheapest Taxi Fare
This problem feels like comparing ride prices in a transport app. You have a list of taxi fares, and you want to choose the cheapest one.
The answer is simply the smallest fare in the list. You do not need to sort the whole list or keep every value. You only need to remember the lowest fare found so far.
For example, if the fares are [45, 30, 38, 50], the answer is 30. That is the cheapest ride price available.
If the list is empty, return -1 because there is no fare to choose from.
Example Input & Output
30 is the lowest fare in the list.
With one taxi option, that fare is automatically the cheapest.
No fares means there is no valid answer.
Algorithm Flow

Solution Approach
A good way to solve this is to keep track of the smallest fare while you go through the list.
First, handle the empty-list case. If there are no fares, return -1.
If there are values in the list, store the first fare in a variable like cheapest. That gives you a starting answer.
Then move through the rest of the fares and compare each one with cheapest.
The update rule is:
Whenever you find a lower fare, replace the saved value. If not, leave it as it is.
After the loop ends, cheapest is the lowest fare in the whole list, so that is the answer you print.
Best Answers
Solutions Coming Soon
Verified best solutions for this Challenge are still being analyzed and will be available soon.
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
