You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the problem 2. add-two-numbers, the iterative solution should have a time and space complexity of:
Time complexity: $O(N)$
Space complexity: $O(N)$
Because the iterations happen till the larger list i.e $N = max(L_1, L_2)$ and in every iteration, there is a new node being created at the line cur.next = ListNode(val) and so the space complexity should also be $O(N)$.
In the problem 2. add-two-numbers, the iterative solution should have a time and space complexity of:
Time complexity:
O
(
N
)
Space complexity:
O
(
N
)
Because the iterations happen till the larger list i.e N = m a x ( L 1 , L 2 ) and in every iteration, there is a new node being created at the line cur.next = ListNode(val) and so the space complexity should also be O ( N ) .
We don't count the output into auxiliary space complexity so the auxiliary space remains O(1). By the way thanks for the feedback, we will add "O(1) due to no extra space but O(n) total space" line into the complexity description for easy understanding.
In the problem
2. add-two-numbers
, the iterative solution should have a time and space complexity of:Because the iterations happen till the larger list i.e$N = max(L_1, L_2)$ and in every iteration, there is a new node being created at the line $O(N)$ .
cur.next = ListNode(val)
and so the space complexity should also bereference
The text was updated successfully, but these errors were encountered: