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

0% completed

Vote For New Content
Time complexity analysis

Pete Stenger

Sep 18, 2024

It takes O(k) time to test if an element exists in an array, not O(1). So the time complexity of this solution is O(n + k^2).

0

0

Comments
Comments
Design Gurus
Design Gurusa year ago

Assuming you are talking about the following line (in python):

if candidateNumber not in extraNumbers:

Here "extraNumbers" is a set (or HashSet) in other languages. The average time complexity of lookup/insert/delete in a set is O(1). If it has been an array, the...

On this page