Skip to content
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

[Enhancement] ContainsDuplicate complexity #1

Open
harshithasudhakar opened this issue Aug 9, 2023 · 0 comments
Open

[Enhancement] ContainsDuplicate complexity #1

harshithasudhakar opened this issue Aug 9, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@harshithasudhakar
Copy link
Owner

harshithasudhakar commented Aug 9, 2023

In ContainsDuplicate.java, the current solution has a time complexity of O(n^2), where n is the number of elements in the array. This can become very slow for larger arrays.

We can still do it solely using arrays, by first sorting the array. Then, iterating through the sorted array and checks if adjacent elements are equal. This can lead to a time complexity of O(n log n).

@harshithasudhakar harshithasudhakar added the enhancement New feature or request label Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant