Leftmost Equilibrium Index
Updated
Problem statement
Return the leftmost zero-based index whose sum of values strictly to its left equals the sum strictly to its right. The value at that index is excluded from both sums.
Return -1 if no index works, including for an empty array. Empty sides have sum zero. Use wide arithmetic for sums.
Function
equilibriumIndex(values: int[]) → intExamples
Example 1
values = [1,3,5,2,2]return = 2The left sum is 1 + 3 = 4, and the right sum is 2 + 2 = 4.
Example 2
values = [1,2,3]return = -1No index has equal excluded-side sums.
Constraints
0 <= values.length <= 100000.-1000000000 <= values[i] <= 1000000000.
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Roll a Weighted DieLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Advertisement Click Range SumsGoogle · ONSITE INTERVIEWGoogle interview questions
- Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Find Pivot IndexMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Product of Array Except SelfWalmart Labs · ONSITE INTERVIEW
- Subarrays Whose Sum Is a Power of TwoKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
- Count Subarrays with Sum KMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
- Product Of Array Except SelfInfosys · ONSITE INTERVIEWInfosys interview questions
- Maximum Subarray Sum with Length at Most KOracle · ONSITE INTERVIEWOracle interview questions