Company: Rippling
Difficulty: medium
# Optimal Periodic Base String You are given a lowercase string `s` and an integer `k`. Construct a lowercase string `t` of exactly length `k`. Imagine the infinite periodic string `t + t + t + ...` Let `copies(t)` be the minimum number of complete copies of `t` whose concatenation contains `s` as a subsequence. Your goal is to minimize `copies(t)`. If several strings `t` achieve the same minimum, output the lexicographically smallest one. Every distinct character that appears in `s` must appear in `t`; otherwise no finite number of copies can contain `s`. ## Input Format - First line: `s` - Second line: `k` ## Output Format Print the lexicographically smallest optimal string `t`. ## Constraints The original submission gave large bounds but did not provide a scalable exact algorithm. This processed version keeps the same objective and uses an exact-search domain: - `1 <= |s| <= 14` - `1 <= k <= 6` - `s` contains at most 5 distinct letters - `k` is at least the number of dis