Ctrl K

Steady Pair Removals

Easy
Cards with numbers lie in a row, given as the array cards. On each move the player takes the first two cards of the row, and the move scores the sum of their numbers. Play continues while at least two cards remain and every move scores exactly as much as the first move. As soon as the next move would score a different sum, the game ends. Return how many moves can be made.
Example 1
cards=[6, 2, 5, 3, 1, 7, 4] → 3

Take 6 and 2 (sum 8), then 5 and 3 (8), then 1 and 7 (8). One card is left, so there are 3 moves.

Example 2
cards=[4, 4, 3, 6, 4, 4] → 1

The first move scores 8, the second would score 9, so the game stops there, even though the last pair would make 8 again.

Example 3
cards=[9, 1] → 1
Constraints
  • 2 ≤ len(cards) ≤ 100
  • 1 ≤ cards[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHow Long the Light Stayed On EasyRepack the Tray EasyQuiz Score Log EasyMirror and Negate a Bitmap EasySwap Rows and Columns Easy
loading Python…
Input
cards=[6, 2, 5, 3, 1, 7, 4]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.