Peak Traffic via reduce()

Medium ⏱ 12 min 64% acceptance ★★★★★ 4.9
Write peak(requests_per_minute) returning the maximum value in a non-empty list using functools.reduce and a lambda — max() on the whole list is banned (the lambda may compare two values however you like).

Examples

Example 1
Input
peak([120, 450, 300])
Output
450
Explanation

reduce keeps the larger of each pair.

Constraints

  • functools.reduce with a two-arg lambda.
  • Input is non-empty.

Topics

Lambda & Functionalreduce

Companies

NetflixAkamaiGoogle

Hints

Hint 1

The accumulator carries the best-so-far.

Hint 2

lambda a, b: a if a > b else b.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.