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

Added-cpp-solution #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

PraneshASP
Copy link
Contributor

No description provided.

Copy link
Owner

@franklingu franklingu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this passes the test. but why this works? seems the complexity is n * n?

@PraneshASP
Copy link
Contributor Author

I know this passes the test. but why this works? seems the complexity is n * n?

Yes it runs at n^2. I uploaded it as it will be easy to understand for beginners. I can also add the solution that has linear time complexity.

@PraneshASP
Copy link
Contributor Author

I updated the code. You may check.

Thanks

@franklingu
Copy link
Owner

this works as well -- except that the run time complexity is bigger than

"Your algorithm should run in O(n) time and uses constant extra space."

this implies modifications of the input array IMO. without this constraint, this problem would be easy

@PraneshASP
Copy link
Contributor Author

Ok.. I accept. Now you can check. I've updated the solution that runs in linear time and with constant space.

@franklingu
Copy link
Owner

it is actually still not o n since u r using sort

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

Successfully merging this pull request may close these issues.

2 participants