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.
Let me explain why it is . Python makes it look simple by hiding lots of complexity on syntactic level. But if you take a closer look - this statement -
ifwordnotinmagazine
has complexity of . Again is size of magazine. Check the complexities here
Also,
magazine.remove(word)
has complexity of , I chose the worst case such that if condition fails everytime and size of magazine is decreasing at each iteration.
Hence actually it is = .
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
This is simple, but very poor on large test cases because its complexity is where is size of
ransom
and is size ofmagazine
Referring - this
Let me explain why it is . Python makes it look simple by hiding lots of complexity on syntactic level. But if you take a closer look - this statement -
has complexity of . Again is size of
magazine
. Check the complexities hereAlso,
has complexity of , I chose the worst case such that
if
condition fails everytime and size ofmagazine
is decreasing at each iteration.Hence actually it is = .