Skip to content

Conversation

@Rfontt
Copy link

@Rfontt Rfontt commented Dec 12, 2025

Description of Change

This PR introduces an implementation of the integer reversal algorithm (reverse_integer) following the project's style and educational guidelines.
The function safely reverses a 32-bit signed integer while preventing overflow by checking against INT32_MAX and INT32_MIN.

  • Added description of change
  • Added a new file reverse_integer in operations_on_datastructures
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes to review:

Time Complexity: O(log₁₀(n))

  • Each loop iteration removes one digit (number = number / 10).
  • An integer with value n has log₁₀(n) digits.
  • Therefore, the loop runs once per digit.

Example:

  • 123 → 3 iterations
  • 123456789 → 9 iterations
  • up to 32-bit max → at most 10 iterations

Space Complexity: O(1)

  • It uses only a fixed number of variables: reversed, digit, and the input itself.
  • No dynamic allocation.
  • No additional data structures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant