Find Total Weight
Stacey is coordinating a beach clean-up event with her university's Women in STEM Charity branch. The beach is covered with tin cans of varying weights arranged in a single line, indexed from 0 to n-1.
Stacey uses a scooper that can pick up three adjacent cans at a time. For each selection:
If multiple cans have the lightest weight, Stacey selects the one with the smallest index. If a can has fewer than two adjacent cans, she removes the available adjacent cans.
Determine the sum of the weights of the lightest cans she picks in each selection.
Complete the function findTotalWeight in the editor with the following parameters:
int cans[n]: the weights of the cans on the beach
Huge thanks to an incredible friend for generously sharing the source 🐳
cans = [5, 4, 1, 3, 2] return = 3
- Array ChallengeOA · Seen Jun 2026
- Minimum Cores to Handle ProcessesOA · Seen Jun 2026
- About ShippingOA · Seen Jun 2026
- Count Dropped RequestsOA · Seen Jan 2026
- Generate Table of ContentsOA · Seen Jan 2026
- Calculate Net ProfitSeen Jun 2025
- Balanced SumSeen Jun 2025
- Count Equal Binary SubstringsSeen Jun 2025
public int findTotalWeight(int[] cans) {
// write your code here
}