Lantern Stall Picks
Think of glowing lantern pieces that need to be handled in the right way. In Lantern Stall Picks, you are trying to work toward the right number by following one clear idea.
Maximize tokens from non-adjacent stalls A good way to think about it is to first understand what goes in, then what rule you must follow, and finally what shape the answer should have.
For example, if the input is tokens = [5,1,1,5], the answer is 10. Choose the first and last stalls to avoid adjacency and earn 10 tokens. Another example is tokens = [2,7,9,3,1], which gives 12. Select stalls worth 2, 9, and 1 tokens for a total of 12.
This is a friendly practice problem, but it still rewards careful reading. The key is understanding the rule clearly and then applying it carefully.
One helpful habit is to say the rule out loud in your own words before you start solving. If you can explain what counts, what changes, and what the final answer should look like, you are already much closer to the right solution.
Example Input & Output
Choose the first and last stalls to avoid adjacency and earn 10 tokens.
Select stalls worth 2, 9, and 1 tokens for a total of 12.
With no stalls, the total reward is zero.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int calculate_max_items(int[] weights, int capacity) {
Arrays.sort(weights);
int count = 0, total = 0;
for (int w : weights) {
if (total + w <= capacity) {
total += w;
count++;
} else break;
}
return count;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
