PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Answer range queries for alternating parity subarrays

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of array manipulation, parity properties, efficient range-query processing, and preprocessing techniques for handling multiple queries.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Answer range queries for alternating parity subarrays

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an integer array `nums` of length `n` and `q` queries. Each query is a pair `[l, r]` (0-indexed, inclusive). A subarray `nums[l..r]` is called **alternating parity** if for every index `i` with `l < i <= r`, `nums[i]` and `nums[i-1]` have **different parity** (one is even and the other is odd). ### Task For each query `[l, r]`, determine whether `nums[l..r]` is alternating parity. Return a boolean array (or an array of `true/false` answers) of length `q`. ### Input/Output - Input: `nums`, `queries` - Output: list of booleans, one per query ### Constraints (reasonable interview assumptions) - `1 <= n, q <= 2*10^5` - Values in `nums` can be negative or positive; parity is based on `abs(nums[i]) % 2`. ### Notes - A subarray of length 0 or 1 is always alternating parity. - You should aim for near `O(n + q)` time overall.

Quick Answer: This question evaluates understanding of array manipulation, parity properties, efficient range-query processing, and preprocessing techniques for handling multiple queries.

Related Interview Questions

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
Google logo
Google
Jan 6, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0
Loading...

Problem

You are given an integer array nums of length n and q queries. Each query is a pair [l, r] (0-indexed, inclusive).

A subarray nums[l..r] is called alternating parity if for every index i with l < i <= r, nums[i] and nums[i-1] have different parity (one is even and the other is odd).

Task

For each query [l, r], determine whether nums[l..r] is alternating parity. Return a boolean array (or an array of true/false answers) of length q.

Input/Output

  • Input: nums , queries
  • Output: list of booleans, one per query

Constraints (reasonable interview assumptions)

  • 1 <= n, q <= 2*10^5
  • Values in nums can be negative or positive; parity is based on abs(nums[i]) % 2 .

Notes

  • A subarray of length 0 or 1 is always alternating parity.
  • You should aim for near O(n + q) time overall.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.