PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Find median of merged RLE arrays

Last updated: Mar 29, 2026

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.

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

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

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.