PracHub
QuestionsLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Google

Deduplicate and Order Batch and Streaming Logs

Last updated: Jul 22, 2026

Quick Overview

Reason through deduplicating unsorted logs under both keep-first and keep-latest semantics, then extend the contract to an online stream. Address deterministic ordering, stale state, timestamp ties, late arrivals, memory growth, finality, watermarks, and exactly-once expectations.

  • medium
  • Google
  • Software Engineering Fundamentals
  • Software Engineer

Deduplicate and Order Batch and Streaming Logs

Company: Google

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

# Deduplicate and Order Batch and Streaming Logs Each log entry is a pair `(timestamp, message)`. Two entries are duplicates when their message strings are equal. Timestamps are integers and input order is not guaranteed to match timestamp order. ### Clarifying Questions to Ask - How should equal timestamps be ordered? - Is message equality byte-for-byte, case-insensitive, or normalized? - Can an entry be corrected or retracted? - For a stream, when is it safe to claim that the next result is final? ### Part 1: Keep the First Encountered Duplicate Given the complete list, retain the first occurrence encountered in input order for each message, regardless of whether a later duplicate has a smaller timestamp. Then return the retained entries from earliest to latest. Define a deterministic tie rule and analyze complexity. #### What This Part Should Cover - A map keyed by exact message identity - Correct preservation of the first input occurrence even when timestamps are unsorted - Deterministic output ordering - Time and memory complexity ### Part 2: Keep the Latest Duplicate Change the rule so each message retains its greatest timestamp. Explain what changes and identify edge cases that should be tested. #### What This Part Should Cover - A safe replacement rule for the retained timestamp - The unchanged need for final ordering - Empty input, repeated identical entries, and timestamp ties ### Part 3: Process an Online Stream Logs now arrive individually. Support `add(timestamp, message)` and `get_next()`, which returns the smallest-timestamp currently available retained entry. First discuss the keep-first rule, then extend it to keep-latest using lazy deletion. State the semantic limitation when late events are allowed. #### What This Part Should Cover - A membership or latest-value map plus a min-heap - Recognition and removal of stale heap entries - Heap growth, compaction, and amortized complexity - Watermarks or lateness bounds for globally final ordering ### What a Strong Answer Covers - Explicit batch and streaming contracts rather than assuming arrival order - Correct deduplication state and deterministic tie behavior - Lazy-deletion invariants and bounded-state considerations - Honest discussion of out-of-order events and finality ### Follow-up Questions - How would you expire deduplication state after a time window? - How would you shard the stream while preserving per-message correctness? - What changes if consumers require exactly-once output? - When should a stale-entry heap be rebuilt?

Quick Answer: Reason through deduplicating unsorted logs under both keep-first and keep-latest semantics, then extend the contract to an online stream. Address deterministic ordering, stale state, timestamp ties, late arrivals, memory growth, finality, watermarks, and exactly-once expectations.

Related Interview Questions

  • Build a Custom CompletableFuture: Async Primitive and Parallel Array Processing - Google (medium)
  • Find the Most Frequent IP Addresses in a File Too Large for Memory - Google (medium)
  • Plan a Safe Repository-Wide Identifier Migration - Google (hard)
  • Process Sharded Login Logs - Google (medium)
|Home/Software Engineering Fundamentals/Google

Deduplicate and Order Batch and Streaming Logs

Google logo
Google
Jul 15, 2026, 12:00 AM
mediumSoftware EngineerOnsiteSoftware Engineering Fundamentals
2
0

Deduplicate and Order Batch and Streaming Logs

Each log entry is a pair (timestamp, message). Two entries are duplicates when their message strings are equal. Timestamps are integers and input order is not guaranteed to match timestamp order.

Clarifying Questions to Ask Guidance

  • How should equal timestamps be ordered?
  • Is message equality byte-for-byte, case-insensitive, or normalized?
  • Can an entry be corrected or retracted?
  • For a stream, when is it safe to claim that the next result is final?

Part 1: Keep the First Encountered Duplicate

Given the complete list, retain the first occurrence encountered in input order for each message, regardless of whether a later duplicate has a smaller timestamp. Then return the retained entries from earliest to latest. Define a deterministic tie rule and analyze complexity.

What This Part Should Cover Guidance

  • A map keyed by exact message identity
  • Correct preservation of the first input occurrence even when timestamps are unsorted
  • Deterministic output ordering
  • Time and memory complexity

Part 2: Keep the Latest Duplicate

Change the rule so each message retains its greatest timestamp. Explain what changes and identify edge cases that should be tested.

What This Part Should Cover Guidance

  • A safe replacement rule for the retained timestamp
  • The unchanged need for final ordering
  • Empty input, repeated identical entries, and timestamp ties

Part 3: Process an Online Stream

Logs now arrive individually. Support add(timestamp, message) and get_next(), which returns the smallest-timestamp currently available retained entry. First discuss the keep-first rule, then extend it to keep-latest using lazy deletion. State the semantic limitation when late events are allowed.

What This Part Should Cover Guidance

  • A membership or latest-value map plus a min-heap
  • Recognition and removal of stale heap entries
  • Heap growth, compaction, and amortized complexity
  • Watermarks or lateness bounds for globally final ordering

What a Strong Answer Covers Guidance

  • Explicit batch and streaming contracts rather than assuming arrival order
  • Correct deduplication state and deterministic tie behavior
  • Lazy-deletion invariants and bounded-state considerations
  • Honest discussion of out-of-order events and finality

Follow-up Questions Guidance

  • How would you expire deduplication state after a time window?
  • How would you shard the stream while preserving per-message correctness?
  • What changes if consumers require exactly-once output?
  • When should a stale-entry heap be rebuilt?
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,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

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.