Code Logo

Pick Cheapest Lunch

Published at19 Apr 2026
Easy 0 views
Like0

This problem comes from a simple lunch decision. You have a list of menu prices, and you want to choose the cheapest option.

The task is not to sort the whole menu or remember every possible order. You only need to find the smallest price in the list.

For example, if the prices are [25, 18, 22, 30], the answer is 18. That is the lowest price among all the lunch options.

If the list is empty, return -1 because there is no lunch option to choose from.

Example Input & Output

Example 1
Input
prices = []
Output
-1
Explanation

No menu options means there is no valid cheapest price.

Example 2
Input
prices = [25, 18, 22, 30]
Output
18
Explanation

18 is the cheapest menu price in the list.

Example 3
Input
prices = [12]
Output
12
Explanation

With only one lunch option, that price is the answer.

Algorithm Flow

Recommendation Algorithm Flow for Pick Cheapest Lunch
Recommendation Algorithm Flow for Pick Cheapest Lunch

Solution Approach

A good method for this problem is almost the same as finding the largest value, except now you are looking for the smallest one.

First, handle the empty-list case. If there are no menu prices, return -1.

If the list has values, store the first price in a variable like cheapest. That gives you a starting answer.

Then move through the rest of the list and compare each price with cheapest.

The update rule is:

if prices[i] < cheapest then cheapest <- prices[i] endif

Whenever you find a smaller value, replace the old one. If not, keep what you already have.

At the end of the loop, cheapest is the lowest lunch price in the 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.