aboutsummaryrefslogtreecommitdiff
path: root/find_lex_large_str_box1.py
blob: 1b29d1faf74618db85a5fce0174238a4d80b6425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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))