Last active
February 12, 2023 10:15
-
-
Save Tr-reny/27cc0a605190b8ddcb62cdf58a3f6a21 to your computer and use it in GitHub Desktop.
The program finds the maximum number of "A"s that can be printed on the screen given a set of keyboard commands and a number of times the keyboard can be pressed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# THis code Finds the max 'A' count with given keyboard presses. | |
def max_a(n): | |
# initialize dp array with size n + 1 | |
dp = [0] * (n + 1) | |
# loop through the dp array | |
for i in range(1, n + 1): | |
# assign the maximum number of 'A' for dp[i] | |
dp[i] = dp[i - 1] + 1 | |
j = 2 | |
while i - j >= 0: | |
dp[i] = max(dp[i], dp[i - j] * (j + 1)) | |
j += 1 | |
# return the maximum number of 'A' | |
return dp[n] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment