Hard
Given a string s, encode it so that its encoded length is as short as possible. The encoding rule is k[encoded_string], where encoded_string is repeated exactly k times. If encoding does not make the string shorter, keep it as-is. When several encodings share the minimum length, return the lexicographically smallest one.
Input: s = "aaa" Output: "aaa"
Input: s = "aaaaa" Output: "5[a]"
Input: s = "aaaaaaaaaa" Output: "10[a]"