This question evaluates string-processing and tree-construction skills, including efficient removal of adjacent or k-sized duplicate groups in strings and building a binary tree from a level-order array to compute properties such as the sum of left leaves.
You are asked three related coding questions.
Given a string s (lowercase English letters), repeatedly remove any pair of adjacent equal characters until no such pair exists.
s
Example:
s = "abbaca"
→ remove
bb
→
aaca
→ remove
aa
→
ca
Constraints (typical): 1 <= |s| <= 1e5.
Given a string s and an integer k, repeatedly remove any group of exactly k adjacent equal characters until no more removals are possible.
s
,
k
Example:
s = "deeedbbcccbdaa", k = 3
→ output
"aa"
Constraints (typical): 1 <= |s| <= 1e5, 2 <= k <= 1e4.
You are given a binary tree in level-order array form (not TreeNode objects). null indicates a missing child. Build the binary tree and compute:
The sum of all left leaf nodes (a left leaf is a leaf node that is the left child of its parent).
arr
of integers and
null
s, in level-order
Example:
arr = [3,9,20,null,null,15,7]
→ left leaves are
9
and
15
→ output
24
Notes: You must construct the tree from the array representation before computing the answer.