Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
In the explanation for the space complexity, why would you ignore the space requ...

Yogi Paturu

Dec 22, 2021

In the explanation for the space complexity, why would you ignore the space required for the output array?

The length of the missingNumbers output array would, at worst, be the length of nums array - 1. This would be if nums is all duplicates of one number.

Any thoughts?

1

0

Comments
Comments
Design Gurus
Design Gurus4 years ago

Right, the same complexity will be O(n) which will be required for the output array.

If the question asks to print all missing numbers, then the space complexity will be O(1).

On this page