PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Google

Design an ads retrieval service using a heap

Last updated: May 1, 2026

Quick Overview

This question evaluates understanding of priority queues/heaps, object-oriented API design, and algorithmic techniques for maintaining dynamic priorities such as add, remove, and update operations.

  • easy
  • Google
  • Software Engineering Fundamentals
  • Software Engineer

Design an ads retrieval service using a heap

Company: Google

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Onsite

## Object-Oriented Design: Ads Retrieval (Priority-Based) Design a component that manages ads and supports retrieving the “best” ads based on a score. ### Requirements Implement APIs such as: - `addAd(adId, score, metadata) -> void` - `removeAd(adId) -> bool` - `updateScore(adId, newScore) -> bool` - `getTopAd() -> Ad | null` (or `getTopK(k) -> List<Ad>`) Assume higher `score` means higher priority. ### Constraints / Expectations - Use a **heap / priority queue** as the main structure. - Discuss **time/space complexity**. - Handle duplicates and updates correctly (e.g., score changes). ### Follow-ups - How do you handle `updateScore` efficiently given that typical heaps don’t support decrease/increase-key by ID? - How do you ensure `getTopAd()` doesn’t return ads that were removed or superseded by a newer score?

Quick Answer: This question evaluates understanding of priority queues/heaps, object-oriented API design, and algorithmic techniques for maintaining dynamic priorities such as add, remove, and update operations.

Related Interview Questions

  • Process Sharded Login Logs - Google (medium)
  • Design a waitlist manager - Google (easy)
  • Design an editable sequence with marker - Google (medium)
  • Design a Dormitory Room-Assignment System (OOD) - Google (medium)
  • Design a waitlist system with top/bottom K - Google (medium)
|Home/Software Engineering Fundamentals/Google

Design an ads retrieval service using a heap

Google logo
Google
Mar 1, 2026, 12:00 AM
easySoftware EngineerOnsiteSoftware Engineering Fundamentals
14
0
Loading...

Object-Oriented Design: Ads Retrieval (Priority-Based)

Design a component that manages ads and supports retrieving the “best” ads based on a score.

Requirements

Implement APIs such as:

  • addAd(adId, score, metadata) -> void
  • removeAd(adId) -> bool
  • updateScore(adId, newScore) -> bool
  • getTopAd() -> Ad | null (or getTopK(k) -> List<Ad> )

Assume higher score means higher priority.

Constraints / Expectations

  • Use a heap / priority queue as the main structure.
  • Discuss time/space complexity .
  • Handle duplicates and updates correctly (e.g., score changes).

Follow-ups

  • How do you handle updateScore efficiently given that typical heaps don’t support decrease/increase-key by ID?
  • How do you ensure getTopAd() doesn’t return ads that were removed or superseded by a newer score?
Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Google•More Software Engineer•Google Software Engineer•Google Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
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.