PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

The question evaluates understanding of run-length encoding, order-statistics (median) computation, and efficient merging of frequency-annotated sequences, emphasizing handling large frequencies without explicit decompression.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Find median of merged RLE arrays

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given two **run-length encoded (RLE)** arrays `A` and `B`. Each is sorted by `value` in non-decreasing order. - Each element is a pair `(value, frequency)` meaning `value` appears `frequency` times in the underlying uncompressed array. - Let `UA` be the uncompressed array represented by `A`, and `UB` similarly for `B`. - Consider the fully merged multiset/array `U = sort(UA ∪ UB)` (i.e., as if you uncompressed both arrays and merged them into one sorted array). Return the **median** of `U`. ## Median Definition Let `N = len(U)`. - If `N` is odd, the median is `U[N//2]` (0-indexed). - If `N` is even, the median is `(U[N//2 - 1] + U[N//2]) / 2`. ## Constraints / Requirements - `frequency` values may be very large, so you must **not** explicitly uncompress the arrays. - `A` and `B` are individually sorted by `value`. ## Example `A = [(1, 2), (5, 1)]` represents `[1, 1, 5]` `B = [(2, 3)]` represents `[2, 2, 2]` Merged: `[1, 1, 2, 2, 2, 5]` → median is `(2 + 2) / 2 = 2`

Quick Answer: The question evaluates understanding of run-length encoding, order-statistics (median) computation, and efficient merging of frequency-annotated sequences, emphasizing handling large frequencies without explicit decompression.

Return the median of the sorted multiset represented by two sorted run-length encoded arrays without expanding them.

Constraints

  • A and B are sorted by value
  • frequencies are positive

Examples

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

Expected Output: 2.0

Explanation: Prompt example.

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

Expected Output: 1.5

Explanation: Even total with average.

Input: ([], [(7, 5)])

Expected Output: 7

Explanation: One side empty.

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

Expected Output: 2

Explanation: Odd total.

Hints

  1. Walk the RLE runs in value order and stop when median indices are reached.
Last updated: Jun 27, 2026

Loading coding console...

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.

Related Coding Questions

  • Infection Spread on a Grid (Cellular Automaton) - Google (hard)
  • Boolean Expression Tree with Leaf Flips - Google (medium)
  • Streaming Points: Remove Any Pair Within a Distance - Google (medium)
  • Most Active Users in a Live Communication Stream - Google (medium)
  • Solve Rooms and Top-K Streams - Google (medium)