Special Keyboard
Reported by candidates from Zomato's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Zomato OA, reported in July 2026, is treating Ctrl-A, Ctrl-C and Ctrl-V as three separate decisions. Candidates simulate the keyboard state and the search blows up. This is the Special Keyboard problem: given n key presses, return the maximum number of A characters on screen. It's a dynamic programming question wearing a keyboard costume. The n = 7 example returns 9, and that number is your sanity check. If you blank on the recurrence during the live assessment, StealthCoder runs invisibly as a safety net and gives you the solution while you keep your cool.
The problem
You have a special keyboard with four keys: Key 1 prints A on the screen. Key 2 performs Ctrl-A and selects the whole screen. Key 3 performs Ctrl-C and copies the current selection into a buffer. Key 4 performs Ctrl-V and appends the buffer to the screen. Given an integer n, return the maximum number of A characters that can be produced using exactly n key presses. Function maxAWithSpecialKeyboard(n: int) → int Examples Example 1 n = 7 return = 9 One optimal sequence is A, A, A, Ctrl-A, Ctrl-C, Ctrl-V, Ctrl-V, producing 9 copies of A. The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: a copy-paste burst costs three presses (select, copy, then at least one paste), and every extra paste adds the same buffer again. So define dp[i] as the max A's using i presses. Base choice: dp[i] = dp[i-1] + 1. Then for each j from 1 to i-3, dp[i] = max(dp[i], dp[j] * (i - j - 1)). Here j is where you stop typing, the next two presses are Ctrl-A and Ctrl-C, and the remaining i-j-2 presses are pastes. The total becomes dp[j] * (i-j-1), counting the original. The common pitfall is an off-by-one in that multiplier, or modeling the buffer and screen as separate states. Check n = 7 by hand: dp[3] = 3, and 3 * (7-3-1) = 9. That matches. It runs in O(n^2) time with O(n) space. If the recurrence slips away mid-assessment, StealthCoder is your hedge for the live OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Special Keyboard 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Zomato's OA.
Zomato reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Special Keyboard FAQ
What's the trick in Zomato's Special Keyboard problem?+
Collapse Ctrl-A, Ctrl-C and Ctrl-V into one block. Pick a point j where you stop typing A's, spend two presses on select and copy, then paste with the rest. dp[i] = max(dp[i-1] + 1, dp[j] * (i-j-1)) over all valid j.
How hard is this problem really?+
Medium. The code is about ten lines, but deriving the recurrence is the hard part. Once you see that only the last block of pastes matters, it's a standard one-dimensional DP with a nested loop.
How do I verify my answer quickly?+
Use the given sample. For n = 7 the answer must be 9. Also check small cases by hand: n up to 6 should return n, since copying doesn't pay off until you have enough presses to recoup the two overhead keys.
What's the time complexity I should aim for?+
O(n^2) time and O(n) space is the standard solution and is usually fine. A closed-form or greedy approach exists using repeated multiplication by 3, 4 or 5 blocks, but the DP is safer to write under pressure.
How do I prepare for this in 48 hours?+
Write the DP from scratch twice without notes. Then trace n = 7 and a few other values by hand. Practice explaining why a paste block costs j+2 presses before the multiplier. That reasoning is what you'll blank on, not the loop.