PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Google

Solve several streaming, DAG, and DP tasks

Last updated: May 1, 2026

Quick Overview

This multi-part question evaluates proficiency in streaming and online algorithms, DAG-based scheduling and parallelism reasoning, and constrained dynamic programming/optimization for sliding-window resource limits, within the Coding & Algorithms domain.

  • hard
  • Google
  • Coding & Algorithms
  • Machine Learning Engineer

Solve several streaming, DAG, and DP tasks

Company: Google

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You were asked multiple algorithmic questions. ## 1) Streaming longest subarray with average `S` You receive an infinite stream of integers (can be positive or negative). A real number `S` is given. After each new integer arrives, output the **longest contiguous subarray within the elements seen so far** whose **average equals `S`**. Clarify/assume for the interview version: - If multiple longest subarrays exist, return any one (or the earliest). - Output can be the length, or `(start_index, end_index)`. - You should process elements online (do not re-scan the entire prefix each time). ## 2) Task scheduling on a dependency graph (DAG) You are given `N` tasks. Each task `i` has a duration `time[i]`. Some tasks depend on others, forming a **directed acyclic graph (DAG)**. ### (a) Single worker / unlimited worker time computation Compute the total time required to finish all tasks subject to dependencies. (Interviewers often clarify one of these variants; state which you’re solving.) - Variant A: **Unlimited parallelism** (tasks can run in parallel as long as dependencies are satisfied). Output the **minimum makespan**. - Variant B: **Single worker** (only one task at a time). Output the **minimum time** (or any valid schedule length). ### (b) `M` parallel workers Now you have `M` identical workers that can run tasks in parallel when dependencies are met. Compute the total completion time. (Again clarify/assume): - Either compute the **optimal** makespan (typically requires small `N`), or - Compute the makespan under a specified policy (e.g., always start any available tasks when a worker is free). ## 3) Max-revenue ad selection with sliding-window constraint You have a time-ordered sequence of ads over `N` time slots. Ad `i` has revenue `r[i]`. Choose which ads to show (e.g., pick a subset of positions, keeping the original order) to maximize total revenue, subject to: - For **every consecutive window of `T` time slots**, the **total revenue of the shown ads inside that window** is **≤ `M`**. Follow-up: - How does your approach change if ads can be **repeated** (i.e., you are allowed to reuse the same ad creative/type multiple times in the overall schedule)?

Quick Answer: This multi-part question evaluates proficiency in streaming and online algorithms, DAG-based scheduling and parallelism reasoning, and constrained dynamic programming/optimization for sliding-window resource limits, within the Coding & Algorithms domain.

Related Interview Questions

  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Solve Shortest Paths and Rental Allocation - Google (medium)
  • Solve Two Array Optimization Problems - Google (medium)
Google logo
Google
Jan 6, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
6
0
Loading...

You were asked multiple algorithmic questions.

1) Streaming longest subarray with average S

You receive an infinite stream of integers (can be positive or negative). A real number S is given.

After each new integer arrives, output the longest contiguous subarray within the elements seen so far whose average equals S.

Clarify/assume for the interview version:

  • If multiple longest subarrays exist, return any one (or the earliest).
  • Output can be the length, or (start_index, end_index) .
  • You should process elements online (do not re-scan the entire prefix each time).

2) Task scheduling on a dependency graph (DAG)

You are given N tasks. Each task i has a duration time[i]. Some tasks depend on others, forming a directed acyclic graph (DAG).

(a) Single worker / unlimited worker time computation

Compute the total time required to finish all tasks subject to dependencies.

(Interviewers often clarify one of these variants; state which you’re solving.)

  • Variant A: Unlimited parallelism (tasks can run in parallel as long as dependencies are satisfied). Output the minimum makespan .
  • Variant B: Single worker (only one task at a time). Output the minimum time (or any valid schedule length).

(b) M parallel workers

Now you have M identical workers that can run tasks in parallel when dependencies are met.

Compute the total completion time.

(Again clarify/assume):

  • Either compute the optimal makespan (typically requires small N ), or
  • Compute the makespan under a specified policy (e.g., always start any available tasks when a worker is free).

3) Max-revenue ad selection with sliding-window constraint

You have a time-ordered sequence of ads over N time slots. Ad i has revenue r[i].

Choose which ads to show (e.g., pick a subset of positions, keeping the original order) to maximize total revenue, subject to:

  • For every consecutive window of T time slots , the total revenue of the shown ads inside that window is ≤ M .

Follow-up:

  • How does your approach change if ads can be repeated (i.e., you are allowed to reuse the same ad creative/type multiple times in the overall schedule)?

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Machine Learning Engineer•Google Machine Learning Engineer•Google Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.