Maximum number of A's using four keys | FACE Prep
Published on 11 Mar 2020
Program to print maximum number of A's using four keys is discussed here.
You are given a task to print maximum As with the given number of keystroke. There are four keys you use
- You can directly press A.
- You can select all the A that has been printed till now using the select all key. (Ctrl + A)
- You can copy the selected text. (Ctrl + C)
- You can paste the copied text. (Ctr + V)
- Now, once copied, you can paste it any number of time but each time it will take one keystroke.
Sample Input: 7 (Number of times we can press the key)
Sample Output: 9
A A A Ctrl+A Ctrl+C Ctrl+V Ctrl+V
By following this sequence, A can be printed 9 times.
Algorithm to print maximum number of A's using four keys
- Input N, number of times the key can be used.
- For N <= 6, return N as the maximum value.
- For N > 6, try all combinations and store the value in a temporary variable.
- Keep updating the temporary variable until all combinations have been applied.
- Print the temporary variable.
Program to print the maximum number of A's using the given keys
Test Case 1
Test Case 2
Test Case 3
Test Case 4
Test Case 5
If you have any feedback about this
article and want to improve this, please write to firstname.lastname@example.org