Skip to content

3403. Find the Lexicographically Largest String From the Box I #1766

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the lexicographically largest string from a box that contains all possible non-empty substrings obtained by splitting the given string into numFriends non-empty contiguous parts in all distinct ways. The key insight is recognizing that the lexicographically largest string in the box must be a contiguous substring of the original string with a maximum length of n - numFriends + 1, where n is the length of the string.

Approach

  1. Special Case Handling for Single Friend: If numFriends is 1, the only possible split is the entire string itself, so we directly return the entire string.
  2. Determine Maximum Length: For other cases, calculate the maximum possible length of any substrin…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Jun 4, 2025
Maintainer Author

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Jun 4, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jun 4, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants