This is a verified interview question from Zomato. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Smallest String With Swaps - Zomato" covers key patterns like Strings.
"You are given a string s that has lowercase English characters. You are also given an integer n. You need to generate a string x of the given length n such that: * All of the distinct characters present in s must be present in the string x. * We will then make a string t by repeatedly adding the string x to it until the string t can be rearranged to have the string s as a substring. * The generated string t should be of the minimum possible length. * If there are multiple possible t with the same length, the string x should be chosen so that the generated string t is the lexicographically smallest possible. Return the string x that would generate the string t. Return empty string if no such string x exists."
Join thousands of developers practicing for Zomato.