-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix sort testcase input sorted unintentionally #256
Conversation
A slice is a references to its underlying array. If a slice is passed as an argument and modified in a function, the original slice is also modified. As getSortedVersion and other sorting functions modify a given slice, testcase inputs are unintentionally sorted beforehand. To avoid that, passes a cloned slices to these functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All seems good to me. Maybe add a comment on top of getSortedVersion
and cloneIntSlice
to make it easier to understand what is happening, even though it's mostly self explanatory.
This timeout is caused by fixing an issue that slices of testcases were unintentionally being sorted. If array is sorted, the complexities of bubble sort and insertion sort are O(n), but in general they are O(n^2) and 500k is large enough to cause timeout.
125e574
to
0bbc1db
Compare
@tjgurwara99 Now that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work catching that unintentional sorting!
Co-authored-by: Taj <tjgurwara99@users.noreply.github.com>
This issue has been resolved recently when I was restructuring the repo - I completely forgot that there was a PR open on that exact same issue of test cases being sorted resulting in false passes. If I remembered I would have merged your PR but since this has been resolved, I am closing this now. |
As
getSortedVersion
and other sorting functions modify a given slice, testcase inputs are unintentionally sorted beforehand.To avoid that, passes a cloned slices to these functions.