PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|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 waitlist system with top/bottom K - Google (medium)
  • Implement matrix transforms and discuss eigenvalues - Google (medium)
Google logo
Google
Mar 1, 2026, 12:00 AM
Software Engineer
Onsite
Software Engineering Fundamentals
9
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?

Solution

Show

Comments (0)

Sign in to leave a comment

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
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.