Explore
ProGrad Programs
Placement Prep
TCS Codevita
Live Placement Training
Live Aptitude Training
Live Programming Training
Webinars
About Us

Edit
Reply




Edit

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.


DESCRIPTION:


You are given a task to print maximum As with the given number of keystroke. 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. (Ctr + V)
  5. Now, once copied, you can paste it any number of time 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.


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


C++

Output
Input - 8 Output - 12


Test Case 1

I/P

8

O/P

12


Test Case 2

I/P

20

O/P

324


Test Case 3

I/P

50

O/P

1327104


Test Case 4

I/P

100

O/P

1946157056


Test Case 5

I/P

67

O/P

150994944


Recommended Programs





If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in
Explore 'c plus plus'
Articles Practice Exercises