text of lowercase English letters and an integer times. A string pattern is *woven in* times times if writing pattern out times times in a row gives a string you can get from text by crossing out some letters (possibly none) while keeping the rest in order.
For example, ba is woven into xbyaba twice: keeping baba from the text does it.
Find the longest string woven into text times times. If several strings tie for the longest, return the one that comes last alphabetically. If no non-empty string works, return the empty string.text="tomtomtamtam", times=2 → 'tmtm'
Writing tmtm twice gives tmtmtmtm: the first four letters come from tomtom, the next four from tamtam. No pattern longer than four letters fits twice.
text="xyyxzx", times=3 → 'x'
Only the letter x occurs three times, so no pattern longer than one letter can fit three times.
text="abcd", times=2 → ''
All letters are different, so not even a single letter fits twice and the answer is the empty string.
times ≤ 2000text) ≤ 2000text) < 8 · timestext consists of lowercase English letterstext="tomtomtamtam", times=2
'tmtm'
Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.