Skip to content

Commit 89afcc3

Browse files
authored
Create Find the Lexicographically Largest String From the Box I.java
1 parent a15f0c9 commit 89afcc3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public String answerString(String word, int numFriends) {
3+
if (numFriends == 1) {
4+
return word;
5+
}
6+
int n = word.length();
7+
String result = "";
8+
for (int i = 0; i < n; i++) {
9+
String curr = word.substring(i, Math.min(i + n - numFriends + 1, n));
10+
if (result.compareTo(curr) <= 0) {
11+
result = curr;
12+
}
13+
}
14+
return result;
15+
}
16+
}

0 commit comments

Comments
 (0)