Maximize the Lottery ID
Updated
Problem statement
The newspaper HackerRankNews distributed lottery tickets to everyone, and the winning lottery ID is described in the paper denoted by winnerID.
In order to win the lottery, a customer having a lottery ID denoted by lotteryID needs to maximize the length of the longest common subsequence of the strings lotteryID and winnerID. To do so, the customer can perform up to k operations. In each operation, the customer can change any character in lotteryID either to its next or previous character.
Find the maximum possible length of the longest common subsequence after at most k such operations.
Note:
- Operations can be performed only on
lotteryID, not onwinnerID. - The next character of a given character
chis the character that comes just after it in the alphabet. Similarly, the previous character is the character that comes just before it in the alphabet. For example, the next character of 'm' is 'n' and the previous is 'l'. For 'z' the next character is 'a' and for 'a' the previous character is 'z'.
Function
maximizeLotteryID(lotteryID: String, winnerID: String, k: int) → intExamples
Example 1
lotteryID = "fpelqanxyk"winnerID = "hackerrank"k = 6return = 7One of the optimal ways to perform the operations is as follows:
- Select
i = 0and movelotteryID[0]to its next character:"gpelqanxyk". - Select
i = 0again:"hpelqanxyk". - Select
i = 2and movelotteryID[2]to its previous character:"hpdlqanxyk". - Select
i = 2again:"hpclqanxyk". - Select
i = 3and movelotteryID[3]to its previous character:"hpckqanxyk". - Select
i = 4and movelotteryID[4]to its next character:"hpckranxyk".
The transformed lottery ID and winnerID have a longest common subsequence of length 7; for example, "hckrank". Therefore, the maximum possible length after at most k operations is 7.
Constraints
1 <= lotteryID.length, winnerID.length <= 1000 <= k <= 200
More Citadel interview questions
- Merge Price-Delta FeedsPHONE SCREEN · Seen Dec 2026
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Possible MEX Values After One Optional IncrementOA · Seen Oct 2026
- Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
- Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
- Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Minimum Merge ConflictsAmazon · OA
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- String Formation (Also for AI/ML Software Engineer Intern :)Snowflake · OASnowflake interview questions
- Longest Subsequence which is a SubstringSalesforce · OASalesforce interview questions
- Distinct MovesMeesho · OA
- Compressed Representation SizeMicrosoft · OAMicrosoft interview questions
- Find Minimum OperationsIBM · OAIBM interview questions
- String Challenge (Generic)TikTok · OATikTok interview questions
- Sum of All ValuesFlexport · OAFlexport interview questions
- Maximum Crayon Removal ScoreWells Fargo · OAWells Fargo interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences