PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Solve order-statistics and XOR-triplet problems

Last updated: Jun 2, 2026

Quick Overview

This multi-part question evaluates skills in order-statistics and efficient counting for array inversion-like problems, alongside bitwise manipulation and prefix-XOR reasoning for combinatorial triplet counting.

  • hard
  • Google
  • Coding & Algorithms
  • Software Engineer

Solve order-statistics and XOR-triplet problems

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are given two separate algorithmic problems. ## Problem 1: Count smaller elements to the right Given an integer array `nums` of length `n`, for each index `i` compute the number of indices `j > i` such that `nums[j] < nums[i]`. - **Input:** `nums` (may contain duplicates and negative values) - **Output:** an array `ans` of length `n`, where `ans[i]` is the count of smaller elements strictly to the right of `i` - **Constraints (typical interview scale):** `1 ≤ n ≤ 10^5`, `|nums[i]| ≤ 10^9` - **Expectation:** design an appropriate data structure / approach to meet an efficient time bound (e.g., ~`O(n log n)`), and be ready to discuss complexity and edge cases. ## Problem 2: Count triplets satisfying an XOR inequality on subarray XORs You are given `n` integers `a1, a2, ..., an` (`1 ≤ n ≤ 10^5`, `0 ≤ ai ≤ 10^9`). Define the function - `F(i, j) = ai XOR a(i+1) XOR ... XOR aj` for `1 ≤ i ≤ j ≤ n`. Count the number of index triplets `(x, y, z)` with `1 ≤ x ≤ y ≤ z ≤ n` such that: - `F(x, y) XOR F(y, z) > F(x, z)`. Notes: - `XOR` is the bitwise exclusive-or. - The output should be the **count** of valid triplets (an `O(n^3)` enumeration is not acceptable for the given constraints). - You may assume the answer fits in 64-bit signed integer unless otherwise specified. - Interview expectation: simplify using prefix XOR and reason about the inequality bit-by-bit to derive an efficient algorithm.

Quick Answer: This multi-part question evaluates skills in order-statistics and efficient counting for array inversion-like problems, alongside bitwise manipulation and prefix-XOR reasoning for combinatorial triplet counting.

Related Interview Questions

  • Busiest Rental Car - Google (easy)
  • Deterministic Task Execution Order - Google (easy)
  • Find Common Free Time Slots Across Calendars - Google (easy)
  • Count Clusters of 2D Points Within a Radius - Google (medium)
  • Infection Spread on a Grid (Cellular Automaton) - Google (hard)
|Home/Coding & Algorithms/Google

Solve order-statistics and XOR-triplet problems

Google logo
Google
Jan 22, 2026, 12:00 AM
hardSoftware EngineerOnsiteCoding & Algorithms
17
0
Practice Read
Loading...

You are given two separate algorithmic problems.

Problem 1: Count smaller elements to the right

Given an integer array nums of length n, for each index i compute the number of indices j > i such that nums[j] < nums[i].

  • Input: nums (may contain duplicates and negative values)
  • Output: an array ans of length n , where ans[i] is the count of smaller elements strictly to the right of i
  • Constraints (typical interview scale): 1 ≤ n ≤ 10^5 , |nums[i]| ≤ 10^9
  • Expectation: design an appropriate data structure / approach to meet an efficient time bound (e.g., ~ O(n log n) ), and be ready to discuss complexity and edge cases.

Problem 2: Count triplets satisfying an XOR inequality on subarray XORs

You are given n integers a1, a2, ..., an (1 ≤ n ≤ 10^5, 0 ≤ ai ≤ 10^9). Define the function

  • F(i, j) = ai XOR a(i+1) XOR ... XOR aj for 1 ≤ i ≤ j ≤ n .

Count the number of index triplets (x, y, z) with 1 ≤ x ≤ y ≤ z ≤ n such that:

  • F(x, y) XOR F(y, z) > F(x, z) .

Notes:

  • XOR is the bitwise exclusive-or.
  • The output should be the count of valid triplets (an O(n^3) enumeration is not acceptable for the given constraints).
  • You may assume the answer fits in 64-bit signed integer unless otherwise specified.
  • Interview expectation: simplify using prefix XOR and reason about the inequality bit-by-bit to derive an efficient algorithm.

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
  • AI Coding 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.