Longest Cipher (Intuit India)
Reported by candidates from Intuit's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Intuit's February OA is asking you to find the longest cipher, and the pattern is dynamic programming. You're looking at a string problem where you need to track the maximum length of some subsequence or substring that satisfies a cipher rule. The trick is that brute force enumeration will time out. You need to build up the answer incrementally, storing state as you scan left to right. StealthCoder can feed you the DP recurrence if you blank on the state definition during the live assessment.
Pattern and pitfall
The core move here is recognizing that you can't just count or sort your way through this. You're building a DP table where each cell represents the longest valid cipher ending at or including position i. The common trap is trying to solve it greedily, picking the longest match at each step without considering what comes after. DP forces you to explore all valid paths and keep the maximum. Most candidates miss that the cipher constraint is usually a relationship between adjacent characters, substring length, or character frequency. When you're live and blocked, StealthCoder acts as your pattern anchor, confirming you need memoization or bottom-up DP rather than a different approach entirely.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Longest Cipher (Intuit India) cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Intuit's OA.
Intuit reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Longest Cipher (Intuit India) FAQ
Is this really just a DP problem or could greedy work?+
Greedy fails because picking the longest valid cipher at each step doesn't guarantee the global maximum. You might block a longer solution later. DP explores all valid subproblems and guarantees the optimal answer. That's the key difference.
What state should I track in my DP table?+
Start with dp[i] = longest valid cipher considering characters up to index i. Then check if you can extend it by adding the next character, or start fresh. The exact recurrence depends on the cipher rule, but this base structure works for most variants.
How much time do I actually have for this in a real OA?+
Typically 45-60 minutes for the full OA. You won't have time to debug a failed greedy approach. Recognize the pattern early, code the DP skeleton fast, and test on the examples. That's your win.
What if I can't figure out the exact cipher rule from the problem statement?+
Check the examples closely. Trace through the longest cipher in the sample input by hand. The rule will emerge. If it's still unclear, ask yourself: is it about consecutive characters, frequency, lexicographic order, or substring structure. That narrows it down fast.
Should I write a top-down or bottom-up DP?+
Bottom-up is safer in a live OA. You avoid recursion depth issues and the code feels more linear. Start from index 0, iterate forward, and update your dp array. Memoization works too if you're more comfortable with recursion.