Find the Lexicographically Largest String From the Box I - Problem
You are given a string word and an integer numFriends. Alice is organizing a game for her numFriends friends.
There are multiple rounds in the game, where in each round:
wordis split intonumFriendsnon-empty strings, such that no previous round has had the exact same split.- All the split words are put into a box.
Find the lexicographically largest string from the box after all the rounds are finished.
Input & Output
Example 1 — Basic Case
$
Input:
word = "abc", numFriends = 2
›
Output:
"c"
💡 Note:
Possible splits: ["a","bc"], ["ab","c"]. All substrings: "a", "bc", "ab", "c". Lexicographically largest is "c".
Example 2 — Single Friend
$
Input:
word = "aba", numFriends = 1
›
Output:
"aba"
💡 Note:
Only one split possible: ["aba"]. The answer is the word itself.
Example 3 — Multiple Friends
$
Input:
word = "abac", numFriends = 3
›
Output:
"c"
💡 Note:
Many possible splits into 3 parts. All possible substrings include "a", "b", "c", "ab", "ba", "ac", etc. The largest is "c".
Constraints
- 1 ≤ word.length ≤ 103
- 1 ≤ numFriends ≤ word.length
- word consists of lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input
Word 'abc' with numFriends = 2
2
Process
All possible splits and their substrings
3
Output
Lexicographically largest substring 'c'
Key Takeaway
🎯 Key Insight: The answer is always the lexicographically largest substring of the original word
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code