Practice Maximum Candies You Can Get from Boxes
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Boxes are labeled 0 through n - 1. status[i] is 1 if box i is open and 0 if closed; candies[i] is its candy count; keys[i] lists boxes its keys can unlock; and containedBoxes[i] lists boxes inside it. You initially possess the boxes in initialBoxes. Whenever you can open a box you possess, collect its candies, keys, and contained boxes. A key alone does not give you the box it unlocks. Return the maximum candies you can collect.
Source: Maximum Candies You Can Get from Boxes on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]
16
# Example 2
status = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0]
6
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Candies You Can Get from Boxes.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.