Reverse of a user input number with best time complexity - #415
Open
KrishPanchal17 wants to merge 1 commit into
Open
Reverse of a user input number with best time complexity#415KrishPanchal17 wants to merge 1 commit into
KrishPanchal17 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have changed the code as it was the code in which user input option was not available, so the user cannot input the number He/She wants which makes the code less efficient and also time complexity of that code was high. So I changed few things in the code, my code defines a function reverse_number that takes an integer n and returns its reverse by repeatedly extracting the last digit and adding it to the reversed number. This approach has a time complexity of O(log10(n)), which is considered to be the best time complexity for reversing a number as it processes each digit only once.
The program also handles invalid input by catching the ValueError exception in case the user enters a non-integer value.