Lexicographically Smallest School Assembly
Updated
Problem statement
You are given a lowercase string s and a nonnegative integer k. Rearrange all characters of s so that between any two equal characters there are at least k other characters.
If no valid rearrangement exists, return "-1". Otherwise, return the lexicographically smallest valid rearrangement.
Function
arrangeStudents(s: String, k: int) → StringExamples
Example 1
s = "ddgdghghh"k = 2return = "dghdghdgh"Each repeated class has exactly two other students between consecutive occurrences, and this is the lexicographically smallest valid ordering.
Example 2
s = "aabbcc"k = 2return = "abcabc"Each letter repeats after two intervening characters.
Example 3
s = "aaabc"k = 1return = "abaca"The three a characters are separated by one character each; choosing b before c gives the smallest valid result.
Example 4
s = "aabb"k = 3return = "-1"The string is too short to put three other characters between both copies of each repeated letter.
Example 5
s = "cba"k = 0return = "abc"With no required gap, sorting the characters gives the lexicographically smallest arrangement.
Constraints
1 <= s.length <= 10^5.scontains only lowercase English letters.0 <= k <= 1000.
More Wells Fargo Online Assessment questions
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
- Longest Subsequence That Is a SubstringOA · Seen Jul 2026
- Overloaded Game Account InventoriesOA · Seen Jul 2026
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Greedy and Beam Sentence DecodingMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Reorganize a StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Worker Task Assignment Part 1 - Balance WorkloadStripe · ONSITE INTERVIEWStripe interview questions
- Rearrange a String So Adjacent Characters DifferGoogle · ONSITE INTERVIEWGoogle interview questions
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- Longest Repeated Letter Block with Adjacent SwapsIntuit · OAIntuit interview questions
- Binary CircuitAkuna Capital · OAAkuna Capital interview questions
- Initial Public OfferingPoint72 · OAPoint72 interview questions
- Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
- Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions