I knew the base LC 4 problem well enough, but the RLE wrapping genuinely slowed me down.
First, clarify that the RLE arrays represent sorted sequences and that the merged array size is the sum of frequencies. Then, adapt binary search on the shorter array to work with cumulative frequencies, using prefix sums to map positions to values without decompression. Finally, handle edge cases like empty arrays and ensure the partition logic correctly identifies the median.
Pro tip: Mention that you would precompute prefix sums of frequencies to enable O(1) access to the value at any index, and emphasize that the binary search is on the partition index of the shorter array, not on the values themselves.
Confirm the input format, total length, and that the median is defined as the middle element (or average of two middle elements) of the fully merged sorted array. Discuss how to handle even/odd total lengths.
Compute prefix sums of frequencies for each RLE array to allow O(1) retrieval of the value at any index via binary search on the prefix sums. This avoids decompression.
Perform binary search on the partition index of the shorter array (by total length). For each partition, compute the corresponding partition in the other array and check if the max of left parts ≤ min of right parts.
Adjust for empty arrays, partitions at boundaries, and compute the median based on the max of left and min of right elements. Ensure the algorithm runs in O(log(min(m,n))) time.
Explain that the time complexity is O(log(min(m,n))) due to binary search, and space complexity is O(1) extra beyond the prefix sums. Discuss why decompression would be O(m+n) and less efficient.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.