FastPrepFastPrep
Problem Brief

Largest Lexicographical Substring ๐ŸŒฟ

OA

Given two strings A and B, your task is to output the largest lexicographically ordered substring of string B that makes string B a superstring of string A. If no such substring exists, output -1.

A superstring is a string that contains all the characters present in another string, irrespective of their order.

1Example 1

Input
A = "abc", B = "abcab"
Output
"cab"
Explanation
String B is a superstring of string A because it contains all the characters of A in various sequences. Among these sequences, ("cab", "abc", "bca") meet the conditions, and the largest lexicographically ordered substring among them is "cab".

Constraints

Limits and guarantees your solution can rely on.

Unknwon for now ๐Ÿ’
public String getLargestLexicographicalSubstring(String A, String B) {
    // write your code here
}
Input

A

"abc"

B

"abcab"

Output

"cab"

Sign in to submit your solution.