You are given two ascending arrays to merge in place and a separate grouping task:
Part A — In-place merge without known sizes:
-
Array A contains sorted integers followed by empty slots, but the counts m (valid values) and k (empty slots) are not provided. Empty slots are represented by a sentinel (e.g., None). Array B contains n sorted integers. You must merge all values from B into A so that A becomes fully sorted, using O(
-
extra space.
-
Tasks:
-
Describe and implement an O(m+n)-time algorithm that determines m and then performs the merge in place. State assumptions, edge cases (duplicates, negatives, one array empty), and time/space complexity.
-
Follow-up: Can you merge by scanning from the beginning of both arrays instead of from the end? Explain why or why not for an in-place algorithm without extra buffers, and give a concrete example illustrating overwrite/instability or the conditions under which forward merging would work.
Part B — Group strings by uniform cyclic shift:
-
Given an array of lowercase strings, group strings that are equivalent under a uniform cyclic letter shift (wrapping modulo
-
and have the same length. For example, "abc" and "bcd" belong together; "az" and "ba" belong together.
-
Tasks:
-
Define a canonical key/normalization for grouping and implement an algorithm to return all groups.
-
Analyze time and space complexity. Discuss handling of mixed lengths, empty strings, and non-letter characters if present.