DEV Community

loading...

Discussion on: And then the interviewer asks, "Can you do this with less code?"

Collapse
cullylarson profile image
Cully Larson • Edited

Great idea for an article. It's a good reminder that interviewers may want to drill down into a question. Just FYI, the original function is O(n log(n) + n) which is O(n log(n)). It isn't O(n). So your second version is actually quite a bit faster. Also, big-theta (Θ) is different from big-oh.

Collapse
michaelsolati profile image
Michael Solati Author

You're right, it's been a while since I've had to do time complexity, I'll update it.

Collapse
cullylarson profile image
Cully Larson • Edited

I had to double-check myself that n log(n) is higher order than n :)

Forem Open with the Forem app