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.
O(2n) is precisely the same as O(n), see the definition of big O. In general it is not worth optimizing past asymptotic complexity except to take advantage of hardware. From a software perspective, different compilers, systems, environments, and standards is enough of a black box that we really don't know enough to say whether a solution with one or two (non-nested) for loops is better.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
O(2n) is precisely the same as O(n), see the definition of big O. In general it is not worth optimizing past asymptotic complexity except to take advantage of hardware. From a software perspective, different compilers, systems, environments, and standards is enough of a black box that we really don't know enough to say whether a solution with one or two (non-nested) for loops is better.