LeetCode 651, Medium. Topics: Math, Dynamic Programming. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 30 parametrized pytest cases, and a playground notebook:
Problem
Imagine you have a special keyboard with the following keys:
A: Print one 'A' on the screen.
Ctrl-A: Select the whole screen.
Ctrl-C: Copy selection to buffer.
Ctrl-V: Print buffer on screen appending it after what has already been printed.
Given an integer n, return the maximum number of 'A' you can print on the screen with at most n presses on the keys.
Examples
Constraints
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026