A pattern editor for wallpaper backgrounds stores each pattern as a string of tile codes. To save space, it wants the smallest tile that, repeated a whole number of times, rebuilds the string exactly.
Write smallestTile(pattern) that returns the shortest string tile such that pattern equals tile repeated k times for some whole number k >= 1. If nothing shorter works, the answer is pattern itself.
Input: pattern = "abcabcabc" Output: "abc"
abc three times rebuilds it.
Input: pattern = "abcab" Output: "abcab"
ab would need a half copy at the end, which isn't allowed.
1 <= pattern.length <= 10^5pattern contains lowercase letters.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #614 Smallest Repeating Tile. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.