space-complexity

Space Complexity with no variables defined

Space Complexity with no variables defined Question: Suppose I had some code: def foo(forest: list[list[int]]) -> int: return sum([1 for tree in forest for leaf in tree]) In this code, no variables are defined. Everything is evaluated in one line, which means to my knowledge the data isn’t being stored anywhere. Does that mean this …

Total answers: 1

Find palindrome python space complexity?

Find palindrome python space complexity? Question: Given the following code in python which checks whether an string of n size is palindromic: def is_palindromic(s): return all(s[i] == s[~i] for i in range(len(s) // 2)) What is the space complexity of this code? Is it O(1) or O(n)? The all function gets an iterable as a …

Total answers: 2

Does String operation like below uses extra space in python?

Does String operation like below uses extra space in python? Question: If I use the following code to remove spaces from the string S, will it be considered as using extra space/memory? Given ‘S’ string of ‘l’ length . int n = l while i < n if S[i] == ” “: S = S[0:i] …

Total answers: 1