Trains the technique from
LeetCode 2384Largest Palindromic NumberThis 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 sign maker owns a tray of digit tiles, listed as the string tiles, one character per tile. The tiles may be laid out in any order, and tiles that are not wanted stay in the tray, but at least one tile must be laid.
The sign must read the same left to right as right to left. It must also read as an ordinary number, so it may not begin with a 0, with one exception: the sign consisting of the single tile 0 is allowed.
Return the largest number the sign maker can lay out, as a string. A longer sign always beats a shorter one, and among signs of the same length the larger number wins. The tray always allows at least one legal sign.
Example 1
The sign `61616` reads the same in both directions and needs three 6 tiles and two 1 tiles, all of which the tray holds. The 4 tile stays in the tray.
Example 2
Every tile in the tray is a 0, and a sign may not open with a 0 unless it is the single tile `0`, which is the sign laid here.
Example 3
The sign `505` reads the same in both directions, uses both 5 tiles and the 0 tile, and opens with a 5 rather than a 0.
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 largest_mirror(tiles: str) -> str:public String largestMirror(String tiles)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.