diff options
author | Jack Sangdahl <[email protected]> | 2025-06-03 18:12:24 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-03 18:12:24 -0600 |
commit | bc5339f3d4c2251937712cbe65bed32f2e0ab5b6 (patch) | |
tree | 54fcb19d51bd31a097e6dc4e042e5a2b95fdd374 /find_lex_large_str_box1.py | |
parent | 1f8ac6cc00dde99ef3c791671c5388161068af3e (diff) | |
download | leetcode-bc5339f3d4c2251937712cbe65bed32f2e0ab5b6.tar.gz leetcode-bc5339f3d4c2251937712cbe65bed32f2e0ab5b6.zip |
3403. find the lexicographically largest string from the box 1
Diffstat (limited to 'find_lex_large_str_box1.py')
-rw-r--r-- | find_lex_large_str_box1.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/find_lex_large_str_box1.py b/find_lex_large_str_box1.py new file mode 100644 index 0000000..1b29d1f --- /dev/null +++ b/find_lex_large_str_box1.py @@ -0,0 +1,30 @@ +# 3403. Find the Lexicographically Largest String From the Box I + +""" +you are given a string 'word', and an integer 'numFriends'. alice is +organising a game for her 'numFriends' friends. there are multiple rounds in +the game, where each round: 'word' is split into 'numFriends' non-empty +strings such that no previous round has the exact same split, and all the +split words are put into a box. find the lexicographically largest string +from the box after all rounds are finished. +""" + + +class Solution(object): + def answerString(self, word, numFriends): + """ + :type word: str + :type numFriends: int + :rtype: str + """ + n = len(word) + m = n - numFriends + 1 + if numFriends == 1: + return word + return max(word[i : i + m] for i in range(n)) + + +if __name__ == "__main__": + obj = Solution() + print(obj.answerString(word="dbca", numFriends=2)) + print(obj.answerString(word="gggg", numFriends=4)) |