Parity-Alternating Range Queries
Updated
Problem statement
Given an integer array nums and inclusive range queries [left, right], determine whether every adjacent pair inside each queried subarray contains one odd number and one even number.
Return one boolean per query in the original order. A one-element range is always valid.
Function
isAlternatingParity(nums: int[], queries: int[][]) → boolean[]Examples
Example 1
nums = [3,4,1,2,6]queries = [[0,4],[1,3],[2,4]]return = [false,true,false]The first and third ranges contain adjacent even values 2 and 6; range [1,3] alternates.
Example 2
nums = [2]queries = [[0,0]]return = [true]A single value has no violating adjacent pair.
Example 3
nums = [1,1,2,3]queries = [[0,1],[1,3]]return = [false,true]The first range starts with two odd values, while [1,3] is odd-even-odd.
Constraints
1 <= nums.length <= 200000.1 <= queries.length <= 200000.- Each query satisfies
0 <= left <= right < nums.length. -1000000000 <= nums[i] <= 1000000000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Earliest Time to Schedule a MeetingMicrosoft · OAMicrosoft interview questions
- Earliest Common Meeting StartVisa · OAVisa interview questions
- Smallest Most-Lit Street PositionHudson River Trading · OAHudson River Trading interview questions
- Most Visited Sprint MarkerChubb · OAChubb interview questions
- Earliest Common Meeting TimeZipRecruiter · OAZipRecruiter interview questions
- File Download Coverage PercentagePersona · OAPersona interview questions