Predict the Winner
Real-world version: Bundle Claim DuelThe statement here is our own: the same inputs, outputs and technique.
Two auditors clear a row of document bundles. bundles[i] is the page count of the bundle at
position i, and page counts are never negative.
The first auditor moves first and the two then alternate. A move takes the bundle at either end of the row that is left, adds its page count to that auditor's tally, and shortens the row. Play continues until no bundle remains. Both auditors know the whole row from the start and both play as well as possible for their own final tally.
Return true if the first auditor's final tally is at least as large as the second
auditor's, and false otherwise. An equal pair of tallies counts in the first auditor's
favour.
Examples
Example 1
- Input
- bundles = [3,9,1,2]
- Output
- true
With both auditors playing as well as they can, the first ends on 11 pages and the second on 4, so the first is not behind.
Example 2
- Input
- bundles = [4,8,3]
- Output
- false
Best play from both sides ends with the first auditor on 7 pages and the second on 8.
Constraints
- 1 <= bundles.length <= 20
- 0 <= bundles[i] <= 10^7
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def first_auditor_wins(bundles: list[int]) -> bool:public boolean firstAuditorWins(int[] bundles)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 2 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's