Stealth Interview
  • Features
  • Pricing
  • Blog
  • Login
  • Sign up

Leetcode #2212: Maximum Points in an Archery Competition

In this guide, we solve Leetcode #2212 Maximum Points in an Archery Competition in Python and focus on the core idea that makes the solution efficient.

You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Leetcode

Problem Statement

Alice and Bob are opponents in an archery competition. The competition has set the following rules: Alice first shoots numArrows arrows and then Bob shoots numArrows arrows.

Quick Facts

  • Difficulty: Medium
  • Premium: No
  • Tags: Bit Manipulation, Array, Backtracking, Enumeration

Intuition

We must explore combinations of choices, but many branches can be pruned early.

Backtracking enumerates valid candidates while keeping the search space under control.

Approach

Use DFS to build candidates step by step, and backtrack when constraints are violated.

Pruning keeps the exploration practical for typical constraints.

Steps:

  • Define the decision tree.
  • DFS through choices and backtrack.
  • Prune invalid paths early.

Example

Input: numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0] Output: [0,0,0,0,1,1,0,0,1,2,3,1] Explanation: The table above shows how the competition is scored. Bob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47. It can be shown that Bob cannot obtain a score higher than 47 points.

Python Solution

class Solution: def maximumBobPoints(self, numArrows: int, aliceArrows: List[int]) -> List[int]: st = mx = 0 m = len(aliceArrows) for mask in range(1, 1 << m): cnt = s = 0 for i, x in enumerate(aliceArrows): if mask >> i & 1: s += i cnt += x + 1 if cnt <= numArrows and s > mx: mx = s st = mask ans = [0] * m for i, x in enumerate(aliceArrows): if st >> i & 1: ans[i] = x + 1 numArrows -= ans[i] ans[0] += numArrows return ans

Complexity

The time complexity is O(2m×m)O(2^m \times m)O(2m×m), where mmm is the length of aliceArrows\textit{aliceArrows}aliceArrows. The space complexity is O(1)O(1)O(1).

Edge Cases and Pitfalls

Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.

Summary

This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.


Ace your next coding interview

We're here to help you ace your next coding interview.

Subscribe
Stealth Interview
© 2026 Stealth Interview®Stealth Interview is a registered trademark. All rights reserved.
Product
  • Blog
  • Pricing
Company
  • Terms of Service
  • Privacy Policy