Skip to content

Commit ae08e1c

Browse files
authored
Create 3403.py
1 parent a2828eb commit ae08e1c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

3001-3500/3403.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)