Tap here to switch tabs
Problem
Submissions

Problem: Compare Sums of Bitonic Parts

med
30 min
Try to solve the Compare Sums of Bitonic Parts problem.

Statement

You are given a bitonic array of integers nums of length n.

A bitonic array is an array that strictly increases to a single peak element and then strictly decreases. The peak element is included in both the ascending part and the descending part.

Find the peak element and calculate two sums:

  • The sum of all elements in the ascending part from index 00 to the peak element index inclusive.

  • The sum of all elements in the descending part from the peak element index to index n−1n - 1 inclusive.

Return:

  • 00 if the sum of the ascending part is strictly greater than the sum of the descending part.

  • 11 if the sum of the descending part is strictly greater than the sum of the ascending part.

  • −1-1 if the sums of both parts are equal.

Constraints:

  • 3≤n==3 \leq n == nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • nums is a bitonic array.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Compare Sums of Bitonic Parts

med
30 min
Try to solve the Compare Sums of Bitonic Parts problem.

Statement

You are given a bitonic array of integers nums of length n.

A bitonic array is an array that strictly increases to a single peak element and then strictly decreases. The peak element is included in both the ascending part and the descending part.

Find the peak element and calculate two sums:

  • The sum of all elements in the ascending part from index 00 to the peak element index inclusive.

  • The sum of all elements in the descending part from the peak element index to index n−1n - 1 inclusive.

Return:

  • 00 if the sum of the ascending part is strictly greater than the sum of the descending part.

  • 11 if the sum of the descending part is strictly greater than the sum of the ascending part.

  • −1-1 if the sums of both parts are equal.

Constraints:

  • 3≤n==3 \leq n == nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • nums is a bitonic array.