PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Answer parity-alternation range queries

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to reason about array properties and design efficient range-query processing for alternating-parity subarrays, and is commonly asked to assess algorithmic performance and scalability under large n and q.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Answer parity-alternation range queries

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

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 even, one odd). For each query `[l, r]`, determine whether `nums[l..r]` is alternating-parity. ### Input - `nums`: array of integers - `queries`: list of `[l, r]` ### Output - An array of booleans `ans`, where `ans[j]` corresponds to query `queries[j]`. ### Constraints (typical) - `1 <= n, q <= 2*10^5` - `0 <= l <= r < n` - `|nums[i]| <= 10^9` Goal: answer all queries efficiently (faster than checking each subarray element-by-element per query).

Quick Answer: This question evaluates a candidate's ability to reason about array properties and design efficient range-query processing for alternating-parity subarrays, and is commonly asked to assess algorithmic performance and scalability under large n and q.

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
7
0
Loading...

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 even, one odd).

For each query [l, r], determine whether nums[l..r] is alternating-parity.

Input

  • nums : array of integers
  • queries : list of [l, r]

Output

  • An array of booleans ans , where ans[j] corresponds to query queries[j] .

Constraints (typical)

  • 1 <= n, q <= 2*10^5
  • 0 <= l <= r < n
  • |nums[i]| <= 10^9

Goal: answer all queries efficiently (faster than checking each subarray element-by-element per query).

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.