FastPrepSpecial Keyboard
Problems/Special Keyboard

Special Keyboard

Zomato / Eternal logoZomato / Eternal● MediumONSITE INTERVIEW
QuestionFunctionExamples

Problem statement

You have a special keyboard with four keys:

  • Key 1 prints A on the screen.
  • Key 2 performs Ctrl-A and selects the whole screen.
  • Key 3 performs Ctrl-C and copies the current selection into a buffer.
  • Key 4 performs Ctrl-V and appends the buffer to the screen.

Given an integer n, return the maximum number of A characters that can be produced using exactly n key presses.

Function

maxAWithSpecialKeyboard(n: int) → int

Examples

Example 1

n = 7return = 9

One optimal sequence is A, A, A, Ctrl-A, Ctrl-C, Ctrl-V, Ctrl-V, producing 9 copies of A.

The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.

More Zomato / Eternal problems

  • Find the Two Unique NumbersONSITE INTERVIEW · Seen Oct 2026
  • Flipping MatrixONSITE INTERVIEW · Seen Oct 2026
  • Jump Game IVONSITE INTERVIEW · Seen Oct 2026
All Zomato / Eternal interview questionsSee Zomato / Eternal hiring insights
Saved
public int maxAWithSpecialKeyboard(int n) {
  // write your code here
}
Checking account…