Balance Sums by Removing One Element
Updated
Problem statement
Given an integer array nums, choose exactly one index i and remove nums[i].
Return true if there is a choice of i for which the sum of the elements strictly before i equals the sum of the elements strictly after i:
sum(nums[0 .. i - 1]) = sum(nums[i + 1 .. n - 1])
The equality is checked around the removed element's original position. Do not search for a different pivot in the shortened array.
Function
canCreatePivot(nums: int[]) → booleanExamples
Example 1
nums = [2,1,3,1,2]return = trueRemove nums[2] = 3. The left sum is 2 + 1 = 3, and the right sum is 1 + 2 = 3.
Example 2
nums = [1,2,3]return = falseNo removal position has equal sums on its two original sides.
Example 3
nums = [-5,4,-5]return = trueRemove the middle value 4. Both side sums are -5.
Constraints
1 <= nums.length <= 200000.-1000000000 <= nums[i] <= 1000000000.- Use signed 64-bit arithmetic for all sums.
More Google Onsite Interview questions
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Filesystem Entity Total SizeONSITE INTERVIEW · Seen Nov 2026
- Longest Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Count Subarrays with Equal Even and Odd CountsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Maximum Sum Desirable SubarrayGroww · PHONE SCREEN
- Maximum Size Subarray Sum Equals KeBay · PHONE SCREENeBay interview questions
- Count Subarrays with Sum KMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
- Detect a Contiguous Subarray with Target SumMeta · PHONE SCREENMeta interview questions
- Count Subarrays With Target SumAmazon · PHONE SCREEN
- Count Subarrays with Sum KByteDance · PHONE SCREENByteDance interview questions
- Subarray Sum Equals KApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Longest Equal-Zero-One SubarrayMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
- Longest Subarray with a Target SumPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions