PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates array-manipulation skills, cumulative-sum/prefix-sum reasoning, and robustness in handling negative values and duplicates, testing algorithmic problem-solving competency in the Coding & Algorithms domain and focusing on practical application rather than purely conceptual understanding.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Check pivot after removing one element

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an integer array `nums` (values may repeat and may be negative). You must remove **exactly one element** (remove one index). The remaining elements keep their original relative order. A **pivot index** in an array is an index `p` such that: - `sum(array[0 .. p-1]) == sum(array[p+1 .. end])` (i.e., the sum of elements strictly to the left of `p` equals the sum of elements strictly to the right of `p`). Task: Return `True` if there exists a way to remove exactly one element from `nums` such that the resulting array has **at least one** pivot index. Otherwise return `False`. Notes: - The pivot element itself is not included in either sum. - After removal, pivot indices are evaluated on the resulting array of length `n-1`. Example format (not necessarily `True`): - `nums = [2, 1, 3, 1, 2]` - remove one element, then check if any pivot exists in the remaining array. Constraints (you may assume typical interview bounds): `2 <= n <= 2e5`, `-1e9 <= nums[i] <= 1e9`.

Quick Answer: This question evaluates array-manipulation skills, cumulative-sum/prefix-sum reasoning, and robustness in handling negative values and duplicates, testing algorithmic problem-solving competency in the Coding & Algorithms domain and focusing on practical application rather than purely conceptual understanding.

You are given an integer array `nums`. You must remove exactly one element (choose one index to delete). The remaining elements stay in their original relative order. A pivot index in an array is an index `p` such that the sum of elements strictly to the left of `p` equals the sum of elements strictly to the right of `p`. Return `True` if there exists some single element you can remove so that the resulting array has at least one pivot index. Otherwise return `False`. Notes: - The pivot element itself is not included in either sum. - Empty sides have sum `0`. - Pivot indices are checked only after the removal.

Constraints

  • `2 <= len(nums) <= 2 * 10^5`
  • `-10^9 <= nums[i] <= 10^9`
  • The total sum can exceed 32-bit integer range, so sums should be handled with 64-bit arithmetic.

Examples

Input: ([1, 2],)

Expected Output: True

Explanation: Remove either element. The remaining single-element array has index 0 as a pivot because both side sums are 0.

Input: ([2, 1, 1, 2],)

Expected Output: True

Explanation: Remove one of the middle `1`s to get `[2, 1, 2]`. Index 1 is a pivot because the left sum and right sum are both 2.

Input: ([2, 1, 3, 1, 2],)

Expected Output: False

Explanation: No matter which single element is removed, the resulting 4-element array has no pivot index.

Input: ([1, 3, 2, 1, 2],)

Expected Output: True

Explanation: Remove the first `1` to get `[3, 2, 1, 2]`. Index 1 is a pivot because the left sum is 3 and the right sum is also 3.

Input: ([0, -1, 1, 0],)

Expected Output: True

Explanation: Remove `-1` to get `[0, 1, 0]`. Index 1 is a pivot because the left sum and right sum are both 0.

Input: ([3, -1, 2],)

Expected Output: False

Explanation: Removing any one element leaves a 2-element array, and none of the possible results has equal left and right sums at any index.

Hints

  1. Fix an index `i` that stays in the array and imagine it becomes a pivot after one removal. Compare `left_sum` and `right_sum` around `i` before removing anything.
  2. If `left_sum - right_sum = d`, then removing a value `d` from the left side or a value `-d` from the right side would balance the two sides. Use frequency maps while scanning.
Last updated: May 4, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Solve Shortest Paths and Rental Allocation - Google (medium)
  • Solve Two Array Optimization Problems - Google (medium)