Back to course home
0% completed
Vote For New Content
2 Keys Keyboard (medium)
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 arecopied
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
operation), and paste it(1
operations). Now, you have 'AA'. Copy it, and paste it. Total =4
operations.
- Input:
-
Example 2:
- Input:
n = 5
- Expected Output:
5
- Justification: Start with 'A', copy it, and paste it four times. Total =
5
operations.
- Input:
-
Example 3:
- Input:
n = 9
- Expected Output:
6
- Justification: Start with 'A', copy and paste twice (3 operations) to get 'AAA'. Copy 'AAA' and paste it twice (3 operations) to get 'AAAAAAAAA'. Total =
6
operations.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible