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.
Insertion Sort Advanced Analysis
Insertion Sort Advanced Analysis
Sort by
recency
|
353 Discussions
|
Please Login in order to post a comment
The provided template should not expect us to return int. Imagine the case
n, n-1, n-2, n-3, ..., 1
, it will require us n*(n - 1) / 2 swap aka will overflow if you use int for n = 1e5. Converted the return type for the provided code to long solved the problemPassed 6 tests and then gets time limit error
This problem is dumb, imagine getting wrong answer cuz the code itself says it expects an integer and you get overflowed, such a waste of time...
Commented for anyone struggling with the model rather than the coding.