Code RoomBurrows-Wheeler transform
HardPrep Room Coding #4938

Burrows-Wheeler transform

CodingAlgorithms & data structuresSenior–Staff~35 min

An archiver shuffles a message before compressing it, because the shuffle gathers equal characters into clumps that pack well. It appends a $ terminator to the message, a character the message itself never contains, then lists every rotation of the terminated text, sorts that list, and keeps only the final character of each rotation, read from the top of the sorted list to the bottom. Those kept characters, joined in that order, are the code it files away. Messages hold lowercase letters and digits only, and both sort after $, so ordinary character order is all the sort ever needs. Given the code, return the message the archiver began with, without the terminator. An empty code came from no message at all, so return the empty string.

Implement
undo_block_sort(code: str) → str
Examples
in["annb$aa"]out"banana"
in["ard$rcaaaabb"]out"abracadabra"
in["$"]out""
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
["annb$aa"]"banana"not run yetsample
["ard$rcaaaabb"]"abracadabra"not run yetsample
["$"]""not run yetsample