Women in STEM Charity
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[]: the weights of the cans on the beach
Returns
int: the sum of the minimum-weight cans at each selection
Constraints
- 3 ≤ length of cans ≤ 2000
- 1 ≤ cans[i] ≤ 10^5