Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Find the pivot index of a sales list

Python data engineering interview problem. Difficulty: intermediate. Pattern: Searching. About 15 minutes. Part of the Pro drill bank.

Daily sales sit in a list. A 'pivot' day is one where the sum on the left equals the sum on the right. Planning uses it as a mid-campaign checkpoint.

Find the pivot index of a sales list (left sum equals right sum).

Requirements

  • Index i is a pivot if sum(sales[:i]) == sum(sales[i+1:]).
  • If several exist, follow the tests (usually the leftmost).

Constraints

  • sales: list of numbers.
  • The pivot value itself is not part of either sum.

Examples

Input: pivot_index([1, 7, 3, 6, 5, 6]) Output: 3 This input follows the stated rules and produces this output.

Topics: lakebench, python, prefix-sums.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Find the pivot index of a sales list

Interview-style drill: Find the index where the sum of sales to its left equals the sum of sales to its right.

Find the pivot index of a sales list (left sum equals right sum).