Grokking Google Coding Interview
Ask Author
Back to course home

0% completed

Solution: 2 Keys Keyboard

Problem Statement

You're given a notepad that initially displays a single character 'A'. You have two actions available to perform on this notepad for each step:

  • Copy All: It allows you to copy everything on the screen.
  • Paste: You can paste the characters which are copied last time.

Given an integer n, return the minimum number of operations to print the character 'A' exactly n times on the screen.

Examples

  • Example 1:
    • Input: n = 4
    • Expected Output: 4
    • Justification: Start with 'A', copy it (`1

.....

.....

.....

Like the course? Get enrolled and start learning!