Largest Subsequences
Updated
Problem statement
Given a lowercase string s of length n, return an array answer of length n.
For every i from 1 through n, answer[i - 1] must be the lexicographically largest subsequence of s whose length is exactly i.
A subsequence is formed by deleting zero or more characters without changing the order of the remaining characters.
Function
getLargestSubsequences(s: String) → String[]Examples
Example 1
s = "hrw"return = ["w","rw","hrw"]For lengths 1, 2, and 3, the lexicographically largest subsequences are w, rw, and hrw.
Example 2
s = "dbca"return = ["d","dc","dca","dbca"]The best subsequence of each length is d, dc, dca, and the complete string dbca.
Constraints
1 <= s.length <= 3000.scontains only lowercase English letters.
More Cashfree Payments interview questions
Similar questions at other companies
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Modify the StringYahoo · OAYahoo interview questions
- Lexicographically Minimum Stack EncryptionRippling · OARippling interview questions
- Shortest String After Erasing Equal PairsMarshall Wace · OAMarshall Wace interview questions
- Minimum Insertions to Balance a Parentheses StringIBM · OAIBM interview questions
- Remove K Digits for the Smallest NumberNutanix · OANutanix interview questions
- Good Binary StringsBNP Paribas · OA
- Remove K DigitsProcol · PHONE SCREEN
- Remove K DigitsThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Remove K DigitsAmazon · ONSITE INTERVIEW