Maximum number of A’s using four keys

Maximum number of A’s using four keys

The program to print a maximum number of A’s using four keys is discussed here.

Maximum number of A's using four keys


DESCRIPTION:

You are given a task to print a maximum of As with the given number of keystrokes. There are four keys you use

  1. You can directly press A.
  2. You can select all the A that has been printed till now using the select all key. (Ctrl + A)
  3. You can copy the selected text. (Ctrl + C)
  4. You can paste the copied text. (Ctrl + V)
  5. Now, once copied, you can paste it any number of times but each time it will take one keystroke.

For example,

Sample Input: 7 (Number of times we can press the key)

Sample Output: 9

Explanation:

A A A Ctrl+A Ctrl+C Ctrl+V Ctrl+V

By following this sequence, A can be printed 9 times.


face prep pro ad bannerClick here to learn more about FACE Prep PRO


Algorithm to print maximum number of A’s using four keys

  • Input N, the 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

@@coding::1@@


face prep pro ad banner

Recommended Programs


Maximum number of A's using four keys

c