Company: Coding Blocks
Difficulty: medium
There is a cargo ship that contains an unlimited amount of cargo. The ship is ready to sail, and you have a list of N non-negative integers that denote the water level in the sea at i -th points. A wave is defined as continuously increasing or decreasing sequence of water levels. For each wave, you need to calculate the cargo that falls into the sea. The cargo that falls into the sea is determined by the smallest height of the wave and the width (length) of the wave. For example, given A = [1, 2, 6, 4, 2, 3, 1, 8, 9, 7] , it has 6 waves: [1, 2, 6]: Smallest height = 1, Width = 3 → Cargo = 1 * 3 = 3 [6, 4, 2]: Smallest height = 2, Width = 3 → Cargo = 2 * 3 = 6 [2, 3]: Smallest height = 2, Width = 2 → Cargo = 2 * 2 = 4 [3, 1]: Smallest height = 1, Width = 2 → Cargo = 1 * 2 = 2 [1, 8, 9]: Smallest height = 1, Width = 3 → Cargo = 1 * 3 = 3 [9, 7]: Smallest height = 7, Width = 2 → Cargo = 7 * 2 = 14 The total amount of cargo that falls into the sea is: 3 + 6 + 4 + 2 + 2 + 14 = 32 . Input Fo