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.
You are given three coding questions from a phone screen. Solve each independently.
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:
[[1,3],[2,6],[8,10],[15,18]]
[[1,6],[8,10],[15,18]]
Constraints (assume):
1 <= n <= 10^5
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:
"abbaca"
abbaca -> aaca -> ca
"ca"
Constraints (assume):
1 <= |s| <= 10^5
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:
s = "deeedbbcccbdaa", k = 3
"aa"
Constraints (assume):
1 <= |s| <= 10^5
2 <= k <= 10^5