PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Grammarly

Solve interval merge and string dedup problems

Last updated: Mar 29, 2026

Quick Overview

This set of questions evaluates algorithmic reasoning for array and string manipulation, specifically competencies in interval merging, detection and elimination of adjacent duplicates, and handling grouped removals under input and performance constraints.

  • hard
  • Grammarly
  • Coding & Algorithms
  • Software Engineer

Solve interval merge and string dedup problems

Company: Grammarly

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given three coding questions from a phone screen. Solve each independently. ## 1) Merge overlapping intervals **Input:** A list of intervals `intervals`, where each interval is `[start, end]` and `start <= end`. **Task:** Merge all overlapping intervals and return a list of non-overlapping intervals that cover the same ranges. **Output:** The merged intervals, typically sorted by start. **Example:** - Input: `[[1,3],[2,6],[8,10],[15,18]]` - Output: `[[1,6],[8,10],[15,18]]` **Constraints (assume):** - `1 <= n <= 10^5` - Interval endpoints fit in 32-bit signed integers. --- ## 2) Remove adjacent duplicates (pair removal) **Input:** A string `s`. **Task:** Repeatedly remove adjacent duplicate characters when they appear as a pair (e.g., remove "aa"), until no more such pairs exist. **Output:** The final resulting string. **Example:** - Input: `"abbaca"` - Process: `abbaca -> aaca -> ca` - Output: `"ca"` **Constraints (assume):** - `1 <= |s| <= 10^5` - Characters can be treated as ASCII letters/digits. --- ## 3) Remove adjacent duplicates in groups of size k **Input:** A string `s` and an integer `k >= 2`. **Task:** Repeatedly remove any group of **k identical characters that are adjacent**. Continue until no such group exists. **Output:** The final resulting string. **Example:** - Input: `s = "deeedbbcccbdaa", k = 3` - Output: `"aa"` **Constraints (assume):** - `1 <= |s| <= 10^5` - `2 <= k <= 10^5` - Characters can include letters and digits.

Quick Answer: This set of questions evaluates algorithmic reasoning for array and string manipulation, specifically competencies in interval merging, detection and elimination of adjacent duplicates, and handling grouped removals under input and performance constraints.

Related Interview Questions

  • Recover a Rooted Tree from Depth-Annotated Preorder - Grammarly (easy)
  • Deep-Copy a Linked List with Random Pointers - Grammarly (medium)
  • Deep-Copy a Linear Linked List - Grammarly (medium)
  • Reverse a Singly Linked List - Grammarly (medium)
  • Implement a Transactional Key-Value Store - Grammarly (medium)
|Home/Coding & Algorithms/Grammarly

Solve interval merge and string dedup problems

Grammarly logo
Grammarly
Oct 22, 2025, 12:00 AM
hardSoftware EngineerTechnical ScreenCoding & Algorithms
34
0

You are given three coding questions from a phone screen. Solve each independently.

1) Merge overlapping intervals

Input: A list of intervals intervals, where each interval is [start, end] and start <= end.

Task: Merge all overlapping intervals and return a list of non-overlapping intervals that cover the same ranges.

Output: The merged intervals, typically sorted by start.

Example:

  • Input: [[1,3],[2,6],[8,10],[15,18]]
  • Output: [[1,6],[8,10],[15,18]]

Constraints (assume):

  • 1 <= n <= 10^5
  • Interval endpoints fit in 32-bit signed integers.

2) Remove adjacent duplicates (pair removal)

Input: A string s.

Task: Repeatedly remove adjacent duplicate characters when they appear as a pair (e.g., remove "aa"), until no more such pairs exist.

Output: The final resulting string.

Example:

  • Input: "abbaca"
  • Process: abbaca -> aaca -> ca
  • Output: "ca"

Constraints (assume):

  • 1 <= |s| <= 10^5
  • Characters can be treated as ASCII letters/digits.

3) Remove adjacent duplicates in groups of size k

Input: A string s and an integer k >= 2.

Task: Repeatedly remove any group of k identical characters that are adjacent. Continue until no such group exists.

Output: The final resulting string.

Example:

  • Input: s = "deeedbbcccbdaa", k = 3
  • Output: "aa"

Constraints (assume):

  • 1 <= |s| <= 10^5
  • 2 <= k <= 10^5
  • Characters can include letters and digits.

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 9,000+ 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.