Lowest and highest fare

tuples

Lowest and highest fare

Lyft Python Interview Question

Lyft's pricing dashboard shows the cheapest and most expensive fare of the day side by side.

Write a function fare_range(fares) that returns a tuple of two values: the lowest fare and the highest fare. Go through the list only once. The list has at least one fare.

Asked of

  • Data Analyst
  • Data Engineer
  • Data Scientist
  • ML Engineer
  • AI Engineer

Example 1

Input

fares = [18.25, 7.5, 42, 23.1]

Output

[7.5, 42]

Example 2

Input

fares = [12]

Output

[12, 12]

Explanation

In the first example, the cheapest fare is 7.5 and the most expensive is 42.0, so the function returns (7.5, 42.0). In the second example, a single fare is both the lowest and the highest.

Submit also runs 3 hidden test cases that check edge cases.