Skip to content

containsDuplicates() - improve time complexity #29

@ThuyNT13

Description

@ThuyNT13

https://github.com/ThuyNT13/algorithm-practice/blob/master/src/js/arrayDuplicate.js

as noted in: 1f3ef03

@ThuyNT13 keep in mind that there's a time complexity of O(n) to this array.includes function. This could potentially lead to a worst case complexity of O(n^2) for your algorithm, since the includes is nested in a for loop. Consider using a different data structure that's more efficient for membership testing, ie: dictionary or set, which have a search time of O(1).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions