Trains the technique from
LeetCode 3517Smallest Palindromic Rearrangement IThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A bracelet is threaded with lettered beads, written out as the string s. The bracelet already reads the same forwards and backwards.
A jeweller is going to unthread every bead and thread them all back on in some order. The rethreaded bracelet must use exactly the beads that came off, all of them and nothing else, and it must again read the same forwards and backwards.
Of all the rethreadings that qualify, return the one that comes first alphabetically.
Example 1
The beads are two each of a, b, c and d. The word `abcddcba` uses all eight of them and reads the same in both directions.
Example 2
There are two a, two c and a single b. The returned word reads the same in both directions and uses every bead.
Example 3
Four a beads and two b beads are already threaded in the alphabetically first qualifying order, so the bracelet comes back unchanged.
Example 4
Two b beads, two c beads and one a bead. The word `bcacb` uses all five and reads the same in both directions.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def smallest_mirror_word(beads: str) -> str:public String smallestMirrorWord(String beads)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.