JPMorgan ChaseOA #13
Find Sum Weight
估计中等评测数据准备中,可先阅读题面
Stacey is coordinating a beach clean-up project with her university's Women in STEM Outreach 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:
- She identifies the three adjacent cans with weight
w - She uses the scooper to pick up the three cans with
w - She removes them from the beach
- She continues this process until there are no cans left on the beach
For each selection, all cans have the lightest weight. Stacey selects the one with the smallest index that contains three adjacent cans with the lightest weight.
Determine the sum of the weights of the three cans she picks in each selection.
Function Description
Complete the function
findSumWeightin the editor with the following parameter: cans: array of the cans on the beach