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.
Examples
01 ยท Example 1
A = "abc" B = "abcab" return = "cab"
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
Unknwon for now ๐More Google problems
- Fountain SafetyONSITE INTERVIEW ยท Seen Jun 2026
- Consolidate On-Call RotationsOA ยท Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW ยท Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW ยท Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN ยท Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN ยท Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW ยท Seen Apr 2026
- Shortest Path with Mandatory WaypointONSITE INTERVIEW ยท Seen Apr 2026
public String getLargestLexicographicalSubstring(String A, String B) {
// write your code here
}
A"abc"
B"abcab"
expected"cab"
sign in to submit