Company: JPMorgan Chase

Difficulty: medium

Problem Statement

Beach Clean-Up Scooper 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 picks up three adjacent cans at a time. For each selection: She identifies the lightest can remaining on the beach, of weight w . She uses the scooper to pick up that can together with its two adjacent cans. She repeats this until no cans are left on the beach. Two cans are adjacent if they sit next to each other among the cans that are still on the beach - once cans are scooped up, the cans on either side of the gap close together and become neighbours. If several cans tie for the lightest weight, Stacey picks the one with the smallest index. If the lightest can has fewer than two neighbours (because it sits at an end of the line), she simply scoops up whichever neighbours it does have. Determine the sum of the weights of the lightest

More JPMorgan Chase OA questionsInterview experiences