Solve interval merge and string dedup problems
Problem Description
You will be presented with three independent coding questions. Solve each one to the best of your ability.
1. Merge Overlapping Intervals
Given a list of intervals, intervals, where each interval is represented as [start, end] and start <= end, merge all overlapping intervals. The goal is to return a new list of non-overlapping intervals that collectively cover the same ranges as the original input. The output list should typically be sorted by the start of each interval.
Example:
- Input:
[[1,3],[2,6],[8,10],[15,18]] - Output:
[[1,6],[8,10],[15,18]]
Constraints:
- The number of intervals
nis between1and10^5. - Interval endpoints are 32-bit signed integers.
2. Remove Adjacent Duplicates (Pair Removal)
Given a string s, repeatedly remove adjacent duplicate characters that appear as a pair (e.g., "aa"). This process continues until no more such pairs can be removed. Return the final resulting string.
Example:
- Input:
"abbaca" - Process:
abbaca->aaca->ca - Output:
"ca"
Constraints:
- The length of the string
|s|is between1and10^5. - Characters can be treated as ASCII letters or digits.
3. Remove Adjacent Duplicates in Groups of Size K
Given a string s and an integer k (where k >= 2), repeatedly remove any group of k identical adjacent characters. This process should continue until no more such groups exist. Return the final resulting string.
Example:
- Input:
s = "deeedbbcccbdaa", k = 3 - Output:
"aa"
Constraints:
- The length of the string
|s|is between1and10^5. kis between2and10^5.- Characters can include letters and digits.
AI interview prep
Core dilemma
Demonstrating a broad command of fundamental algorithms and data structures, coupled with the ability to write correct, efficient, and clean code under pressure across different problem types.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Solve interval merge and string dedup problems
Problem Description
You will be presented with three independent coding questions. Solve each one to the best of your ability.
1. Merge Overlapping Intervals
Given a list of intervals, intervals, where each interval is represented as [start, end] and start <= end, merge all overlapping intervals. The goal is to return a new list of non-overlapping intervals that collectively cover the same ranges as the original input. The output list should typically be sorted by the start of each interval.
Example:
- Input:
[[1,3],[2,6],[8,10],[15,18]] - Output:
[[1,6],[8,10],[15,18]]
Constraints:
- The number of intervals
nis between1and10^5. - Interval endpoints are 32-bit signed integers.
2. Remove Adjacent Duplicates (Pair Removal)
Given a string s, repeatedly remove adjacent duplicate characters that appear as a pair (e.g., "aa"). This process continues until no more such pairs can be removed. Return the final resulting string.
Example:
- Input:
"abbaca" - Process:
abbaca->aaca->ca - Output:
"ca"
Constraints:
- The length of the string
|s|is between1and10^5. - Characters can be treated as ASCII letters or digits.
3. Remove Adjacent Duplicates in Groups of Size K
Given a string s and an integer k (where k >= 2), repeatedly remove any group of k identical adjacent characters. This process should continue until no more such groups exist. Return the final resulting string.
Example:
- Input:
s = "deeedbbcccbdaa", k = 3 - Output:
"aa"
Constraints:
- The length of the string
|s|is between1and10^5. kis between2and10^5.- Characters can include letters and digits.