Lantern Stall Picks
Festival guests rate lantern stalls from 0 to n, but the operations team only wants to focus on the top contenders. In Lantern Stall Picks, your task is to find the K-th Largest rating in a jumbled list of scores. This helps the organizers decide which stall receives the coveted "Best Glow" award for the night!
The "secret sauce" here is Sorting and Indexing. While you could use complex selection algorithms, the most straightforward way is to sort the list in descending order and pick the value at index k-1. This approach is fast (O(n log n)) and incredibly reliable for any rating range. You must handle duplicate scores (stalls with matching popularity) with care, ensuring every entry is counted. If the list is empty or the rank is out of bounds, return standard safety values. This ensures the awards ceremony stays fair and transparent for all the festival's talented vendors!
If sorting is part of the strategy, do it intentionally as a preprocessing step to simplify downstream logic such as merging, ordering, or comparison. After sorting, keep output semantics precise: preserve expected structure, avoid dropping valid entries, and ensure tied cases still follow deterministic order rules.
Examples
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 problem.
