Tracking current and longest failure streaks

A payment gateway monitors consecutive validation failures. Its state consists of the values carried from one record to the next: the current failure streak and the longest failure streak seen so far.


Both values start at zero. For each record, the algorithm performs these updates in order:

  1. If the result is Fail, increase the current streak by one. If the result is Pass, reset the current streak to zero.
  2. Replace the longest streak with the larger of its previous value and the updated current streak.

Complete the table with both values after both updates for each record. Enter exact integers; each streak is measured in consecutive failed records.

RecordValidation resultCurrent streakLongest streak
1Fail
2Fail
3Pass
4Fail
5Fail
6Fail
7Pass

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Data Algorithms Questions: