2
def minSteps(self, n: int) -> int:3
# at every step we can copy or paste4
# paste -> we need to know the current clipboard content (count)5
# copy -> set clipboard count to current screen count (we should consider it, if the last operation was paste)9
def dfs(clipboard_count, screen_count):10
if (clipboard_count, screen_count) in memo:11
return memo[(clipboard_count, screen_count)]13
# we reached n, this is a valid option17
# we passed n, not a valid option22
copy_opt = paste_opt = float("inf")24
# we should only paste if clipboard is not empty25
if clipboard_count > 0:26
paste_opt = dfs(clipboard_count, screen_count + clipboard_count)28
# we should consider copy only if the last operation was paste29
if screen_count > clipboard_count:30
copy_opt = dfs(screen_count, screen_count)33
memo[(clipboard_count, screen_count)] = 1 + min(paste_opt, copy_opt)34
return memo[(clipboard_count, screen_count)]