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

Binary search exercise solution could be further optimized #13

Open
Kimonili opened this issue Jan 15, 2021 · 0 comments
Open

Binary search exercise solution could be further optimized #13

Kimonili opened this issue Jan 15, 2021 · 0 comments

Comments

@Kimonili
Copy link

Kimonili commented Jan 15, 2021

Instead of linearly searching for all the occurrences we could do that faster by searching them all in a binary way.

Here:

while i >=0:
    if numbers[i] == number_to_find:
        indices.append(i)
    else:
        break
    i = i - 1

And here:

while i<len(numbers):
    if numbers[i] == number_to_find:
        indices.append(i)
    else:
        break
    i = i + 1

I would be happy to make a pull request 😄

PS: Your tutorial playlist on DSA is amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant