We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Python's "in" operator has different time complexities depending on the data structure being used. If it's a list it might reach O(N) very easily, but using a Dictionary - Python's Hashtable - or a Set, both use the __hash__ method, is O(1). It might reach O(N) if the __hash__ is not well implemented just like samirsahu said.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
Python's "in" operator has different time complexities depending on the data structure being used. If it's a list it might reach O(N) very easily, but using a Dictionary - Python's Hashtable - or a Set, both use the __hash__ method, is O(1). It might reach O(N) if the __hash__ is not well implemented just like samirsahu said.