Given keyboard with 4 keys (A, ctrl+A, ctrl+C, ctrl+V), find max number of letters you can type with the given number of keystrokes

#!/usr/bin/env python
 
def maxkeys(n, table):
    if n <= 6:
        table.extend(range(n + 1))
    else:
        maxkeys(n - 1, table)
        table.append(max([v * (n - x - 1) for x, v in enumerate(table) if x <= n - 3]))


t = []
maxkeys(22, t)
print(t)
Advertisements