FunctionRacerProblemsRace

Longest Mirror Material

HardHash mapsPython, JavaScript, TypeScript, Java, C++

text is a string of digits. A stretch of text (characters next to each other) is mirror material when its characters can be put in an order that reads the same from both ends.

Return the length of the longest stretch that is mirror material.

Example 1

text "12213"
returns 5

The whole string works: its digits can be put in the order 12321.

Example 2

text "1232"
returns 3

The stretch 232 works. The whole string does not: both 1 and 3 appear an odd number of times.

Example 3

text "123"
returns 1

No two of the digits are equal, so only single digits work.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems