We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a2828eb commit ae08e1cCopy full SHA for ae08e1c
3001-3500/3403.py
@@ -0,0 +1,28 @@
1
+class Solution(object):
2
+ def answerString(self, word, numFriends):
3
+ """
4
+ :type word: str
5
+ :type numFriends: int
6
+ :rtype: str
7
8
+
9
+ # Step 1: Handle edge case
10
+ if numFriends == 1:
11
+ return word
12
13
+ n = len(word)
14
+ # Step 2: Max allowed length for a single part
15
+ max_len = n - numFriends + 1
16
+ res = ""
17
18
+ # Step 3: Iterate over possible start positions
19
+ for i in range(n):
20
+ end = min(n, i + max_len)
21
+ substr = word[i:end]
22
23
+ # Step 4: Update result if this substring is larger
24
+ if substr > res:
25
+ res = substr
26
27
+ # Step 5: Return the best substring
28
+ return res
0 commit comments