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.
No, it's not. Also, if this were an interview I would get extra points. It is actually 2*n (compared to n), so both are O(n). But you must keep in mind that this is Python, not C++. It IS actually faster to use its functions rather than looping through everything. In fact, it is almost 2x faster. Code for benchmarks:
Also, this is Python. Even if the second was faster, you should pick the first for 90% of the cases. You need less time to figure what it's doing, and is less error-prone.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Birthday Cake Candles
You are viewing a single comment's thread. Return to all comments →
No, it's not. Also, if this were an interview I would get extra points. It is actually 2*n (compared to n), so both are O(n). But you must keep in mind that this is Python, not C++. It IS actually faster to use its functions rather than looping through everything. In fact, it is almost 2x faster. Code for benchmarks:
Also, this is Python. Even if the second was faster, you should pick the first for 90% of the cases. You need less time to figure what it's doing, and is less error-prone.