Class Solution
-
- All Implemented Interfaces:
public final class Solution3403 - Find the Lexicographically Largest String From the Box I.
Medium
You are given a string
word, and an integernumFriends.Alice is organizing a game for her
numFriendsfriends. 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.
A string
ais lexicographically smaller than a stringbif in the first position whereaandbdiffer, stringahas a letter that appears earlier in the alphabet than the corresponding letter inb. If the firstmin(a.length, b.length)characters do not differ, then the shorter string is the lexicographically smaller one.Example 1:
Input: word = "dbca", numFriends = 2
Output: "dbc"
Explanation:
All possible splits are:
"d"and"bca"."db"and"ca"."dbc"and"a".
Example 2:
Input: word = "gggg", numFriends = 4
Output: "g"
Explanation:
The only possible split is:
"g","g","g", and"g".Constraints:
<code>1 <= word.length <= 5 * 10<sup>3</sup></code>
wordconsists only of lowercase English letters.1 <= numFriends <= word.length
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringanswerString(String word, Integer numFriends)-
-
Method Detail
-
answerString
final String answerString(String word, Integer numFriends)
-
-
-
-