↓Skip to main content
  1. LeetCode/

LeetCode 3909: Compare Sums of Bitonic Parts

·1 min· ·
LeetCode Medium Array
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: medium First Attempt: 2026-04-25

  • Submissions: Accepted (first try)

Approach
#

The array strictly rises then falls, so the peak is unique. Left is nums[0..peak] and right is nums[peak..n-1] (Array Template 1). The peak belongs to both, adding the same amount to each side, so it can be left out of the comparison.

My Solution
#

class Solution:
    def compareBitonicSums(self, nums: List[int]) -> int:
        peak = nums.index(max(nums))
        left, right = sum(nums[:peak + 1]), sum(nums[peak:])
        if left > right:
            return 0
        if left < right:
            return 1
        return -1

I originally walked two pointers from both ends toward the peak, summing as they went (without the peak). With a strictly bitonic array the maximum is the peak, so max finds it too.

Complexity
#

Time O(n), space O(n) (slices).

Mistakes to Avoid
#

  • Return values: 0 when the left is larger, 1 when the right is, -1 when equal.

Interview Explanation
#

In a strictly bitonic array the maximum is the peak; I find it, sum both sides, and compare. The peak is on both sides, so it does not affect the result. Time O(n).

Related

LeetCode 3904: Smallest Stable Index II
·1 min
LeetCode Medium Prefix-Sum Array
LeetCode 3904 note: the first index where the prefix maximum minus the suffix minimum is <= k; build the suffix minimum right to left first
LeetCode 522: Longest Uncommon Subsequence II
·2 mins
LeetCode Medium Two-Pointers String Sorting Array Hash-Table
LeetCode 522 note: the longest uncommon subsequence is always a whole string; check strings from longest to shortest, and the first that is not a subsequence of any other long-enough string is the answer
LeetCode 3843: First Element with Unique Frequency
·1 min
LeetCode Medium Hash-Table Counting Array
LeetCode 3843 note: count each value, then count how many values share each count; the first element from the left whose count is its own is the answer
LeetCode 3840: House Robber V
·2 mins
LeetCode Medium Dynamic-Programming Array
LeetCode 3840 note: houses conflict only when adjacent with the same color; take a house outright when the colors differ, and do the House Robber choice only when they match
LeetCode 3719: Longest Balanced Subarray I
·2 mins
LeetCode Medium Hash-Table Prefix-Sum Segment-Tree Array
LeetCode 3719 note: n is only 1500, so fix the left end and extend right, maintaining distinct odds and evens in two sets
LeetCode 3834: Merge Adjacent Equal Elements
·2 mins
LeetCode Medium Stack Simulation Array
LeetCode 3834 note: a stack simulation where a new element merges with an equal top, possibly again with the new top