Skip to content

Reverse of a user input number with best time complexity - #415

Open
KrishPanchal17 wants to merge 1 commit into
souravjain540:mainfrom
KrishPanchal17:main
Open

Reverse of a user input number with best time complexity#415
KrishPanchal17 wants to merge 1 commit into
souravjain540:mainfrom
KrishPanchal17:main

Conversation

@KrishPanchal17

Copy link
Copy Markdown

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.

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.

1 participant