PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Grammarly

Implement string reduction and time map

Last updated: Mar 29, 2026

Quick Overview

This question evaluates skills in string-processing algorithms and time-based data structure design, measuring competency in correctness, efficiency, and handling repeated pattern removals and temporal key-value retrieval.

  • easy
  • Grammarly
  • Coding & Algorithms
  • Software Engineer

Implement string reduction and time map

Company: Grammarly

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

In a coding interview, you are asked to solve two algorithm problems. 1. **String reduction with adjacent duplicates** - Basic version: Given a string `s`, repeatedly remove any adjacent pair of equal characters until no such pair remains. Return the final string. - Follow-up: Given a string `s` and an integer `k`, repeatedly remove any group of `k` adjacent equal characters until no more removals are possible. Return the final string. - Example follow-up: if `s = "deeedbbcccbdaa"` and `k = 3`, the answer is `"aa"`. 2. **Time-based key-value store** - Design a data structure that supports: - `set(key, value, timestamp)`: store a value for a key at a given timestamp. - `get(key, timestamp)`: return the value associated with the largest timestamp less than or equal to the given timestamp for that key. If no such timestamp exists, return an empty string. - Assume timestamps passed to `set` are strictly increasing for each key. - Implement both operations efficiently. Write working code for both problems and explain the time and space complexity of your approach.

Quick Answer: This question evaluates skills in string-processing algorithms and time-based data structure design, measuring competency in correctness, efficiency, and handling repeated pattern removals and temporal key-value retrieval.

Related Interview Questions

  • Implement a Transactional Key-Value Store - Grammarly (medium)
  • Merge overlapping corrections - Grammarly
  • Remove adjacent duplicates and handle tree input - Grammarly (medium)
  • Solve interval merge and string dedup problems - Grammarly (hard)
Grammarly logo
Grammarly
Nov 29, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
8
0

In a coding interview, you are asked to solve two algorithm problems.

  1. String reduction with adjacent duplicates
    • Basic version: Given a string s , repeatedly remove any adjacent pair of equal characters until no such pair remains. Return the final string.
    • Follow-up: Given a string s and an integer k , repeatedly remove any group of k adjacent equal characters until no more removals are possible. Return the final string.
    • Example follow-up: if s = "deeedbbcccbdaa" and k = 3 , the answer is "aa" .
  2. Time-based key-value store
    • Design a data structure that supports:
      • set(key, value, timestamp) : store a value for a key at a given timestamp.
      • get(key, timestamp) : return the value associated with the largest timestamp less than or equal to the given timestamp for that key. If no such timestamp exists, return an empty string.
    • Assume timestamps passed to set are strictly increasing for each key.
    • Implement both operations efficiently.

Write working code for both problems and explain the time and space complexity of your approach.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Grammarly•More Software Engineer•Grammarly Software Engineer•Grammarly 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.