Leetcode Problem 2212. Maximum Points in an Archery Competition
2212. Maximum Points in an Archery Competition
Leetcode Solutions
Backtracking Approach
Define a recursive function that takes the current index (section), remaining arrows, current score, and current distribution of Bob's arrows.
If the index is less than 0 or no arrows remain, check if the current score is greater than the maximum score found so far. If so, update the maximum score and Bob's arrow distribution.
For the current section, decide not to shoot any arrows and recursively call the function for the next section.
If Bob has enough arrows to beat Alice in the current section, decide to shoot one more arrow than Alice, update the remaining arrows and score, and recursively call the function for the next section.
After exploring both options for the current section, backtrack to restore the state for exploring the next section.
Once all sections are considered, if there are leftover arrows, add them to the 0 section as they do not affect the score.