2 Keys Keyboard

MediumMathmath

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A notepad starts with a single character 'A' and an empty clipboard. You have two operations: - **Copy All**: copy the entire current text into the clipboard (replacing what was there). - **Paste**: append the clipboard's contents to the text. Return the minimum number of operations needed to end with exactly n copies of 'A'. For n = 1 no operations are needed.

Examples

Input: n = 3
Output: 3
Copy All, Paste, Paste: A -> AA -> AAA.
Input: n = 1
Output: 0
The notepad already holds one A.

Constraints

  • `1 <= n <= 1000`

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More math problems