Solve the following coding tasks.
1) Merge two sorted arrays in-place
You are given two integer arrays A and B, each sorted in non-decreasing order.
-
A
has length
m + n
, where the first
m
elements are valid, and the last
n
elements are extra space.
-
B
has length
n
.
Task: Modify A in-place so that it becomes a single sorted array containing all m + n elements.
Constraints (typical): 0 ≤ m, n ≤ 2e5, values fit in 32-bit signed int.
2) Right-side view of a binary tree (variant)
Given the root of a binary tree, return the list of node values visible when looking at the tree from the right side (i.e., the last node encountered at each depth when scanning left-to-right).
Task: Output the values from top to bottom.
Constraints (typical): up to 2e5 nodes.
3) Maze problem (multi-part)
You are given a 2D grid representing a maze:
-
'.'
= empty cell,
'#'
= wall
-
'S'
= start,
'E'
= end
-
You can move in 4 directions (up/down/left/right) to non-wall cells.
Tasks:
A. Determine whether a path exists from S to E.
B. If a path exists, return the length of the shortest path (number of moves).
C. Optionally, return one shortest path as a string over {U,D,L,R}.
Constraints (typical): grid size up to 2000 x 2000 (so algorithms should be near-linear in number of cells).