2 Keys Keyboard
A medium-tier problem at 59% community acceptance, tagged with Math, Dynamic Programming. Reported in interviews at Salesforce and 0 others.
You're staring at a keyboard with only two keys: 'A' and 'Ctrl+A', plus 'Ctrl+C' and 'Ctrl+V'. The problem: get exactly n A's in the minimum number of key presses. It sounds trivial until you realize the brute force approach tanks on large n. This problem has shown up at Salesforce and tests whether you can spot the mathematical pattern hiding inside a dynamic programming shell. The trick isn't complex once you see it, but candidates who don't recognize it often burn time on suboptimal solutions. StealthCoder surfaces the optimal path instantly if you blank on the factorization insight during your live assessment.
Companies that ask "2 Keys Keyboard"
2 Keys Keyboard is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.
Get StealthCoderThe core insight is that any sequence of operations can be broken into chunks: select all, copy, then paste multiple times. If you paste k times after one select-copy, you've added k*A's in k+2 presses (one select, one copy, k pastes). The problem reduces to finding the optimal way to partition n into factors, where the cost of a partition is the sum of its factors plus the number of partitions minus one. Most candidates initially try greedy approaches or raw recursion, which fail. The dynamic programming solution tracks the minimum presses to reach each value from 1 to n, and the factorization pattern is what optimizes it. Companies like Salesforce use this to filter for candidates who can recognize when a problem that looks like state-space search actually has a mathematical skeleton. If you hit this live and the greedy approach feels wrong, StealthCoder runs silently and gives you the DP recurrence with the factorization trick.
Pattern tags
You know the problem.
Make sure you actually pass it.
2 Keys Keyboard recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.
2 Keys Keyboard interview FAQ
Is this really asked at FAANG, or just at Salesforce?+
This problem appears in hiring loops at Salesforce and has lower frequency elsewhere in public reports. It's not a tier-1 staple like Two Sum or Buy/Sell Stock, but it does surface at companies that filter for strong math intuition. Acceptance rate sits around 59 percent, suggesting many candidates solve it, but the trick isn't immediately obvious.
What's the trap in the obvious approach?+
Most candidates try greedy: always paste as many times as possible. That fails. Others brute-force all press sequences, which times out. The trap is not recognizing that the problem is really about factorizing n optimally, not simulating keypresses. Once you see it's a factorization problem wrapped in DP, the solution clicks.
How does Math connect to Dynamic Programming here?+
Math provides the insight (factorization minimizes cost), and DP is the framework to compute it. You build a table where each cell represents the minimum presses to reach that number of A's, informed by its divisors. The math tells you which divisors to check; the DP tracks the minimum.
Is this problem still asked, or is it stale?+
Salesforce has reported it, and it remains a viable interview problem because it sits at the intersection of math and optimization. The acceptance rate of roughly 59 percent suggests it's neither too easy nor abandoned. If you're targeting Salesforce or companies with similar filtering, knowing this pattern is a solid edge.
How much time should I spend drilling this if I'm short on prep?+
If you're interviewing at Salesforce or similar, spend 30 to 45 minutes understanding the factorization insight and the DP recurrence. If you're hitting multiple companies, prioritize high-frequency problems first. This is a solid second-tier drill that rounds out your math and DP skills.
Want the actual problem statement? View "2 Keys Keyboard" on LeetCode →