Longest streak of successful payments

arrays

Longest streak of successful payments

Stripe Python Interview Question

Stripe's reliability team tracks how long a merchant's payments keep succeeding before one fails. A long run of successes is a sign that an integration is healthy.

Write a function longest_success_streak(statuses) that takes a list of payment statuses in the order they happened and returns the length of the longest run of back-to-back "succeeded" payments. Return 0 if no payment succeeded.

Asked of

  • Data Engineer
  • Data Scientist
  • Analytics Engineer
  • ML Engineer
  • AI Engineer

Example 1

Input

longest_success_streak(["succeeded", "succeeded", "failed", "succeeded"])

Output

2

Example 2

Input

longest_success_streak(["failed", "failed"])

Output

0

Example 3

Input

longest_success_streak(["succeeded", "failed", "succeeded", "succeeded", "succeeded", "failed"])

Output

3

Explanation

In the first example, the first two payments succeeded before one failed, and the last payment starts a new run of 1, so the longest run is 2. In the second example no payment succeeded, so the answer is 0.