Skip to content

Conversation

@momstrosity
Copy link

@momstrosity momstrosity commented May 22, 2025

Implement Manual String Reversal Function Without Built-in Methods

Description

Task

Implement String Reversal Function

Acceptance Criteria

  • Function should take a string input and return its reverse
  • Should handle empty strings
  • Should preserve spaces and special characters
  • Should be implemented without using string[::-1] or reverse()

Summary of Work

Overview

This pull request implements a custom string reversal function that meets the following key requirements:

  • Reverses a string without using built-in reversal methods like [::-1] or reverse()
  • Handles various input scenarios
  • Provides robust error handling

Changes Made

  • Implemented reverse_string() function in src/string_reversal.py
  • Used a two-pointer technique for manual string reversal
  • Maintained comprehensive test coverage

Implementation Details

Approach

  • Convert input string to a list of characters
  • Use two pointers (left and right) to swap characters
  • Iterate until pointers meet in the middle
  • Convert modified list back to a string

Key Features

  • O(n) time complexity
  • In-place character swapping
  • Type checking for input validation
  • Handles edge cases like:
    • Empty strings
    • Single characters
    • Strings with special characters
    • Unicode strings

Testing

  • All existing test cases pass
  • Verified functionality across multiple input types
  • Comprehensive test suite covers:
    • Normal string reversal
    • Empty string handling
    • Special character support
    • Unicode character support
    • Invalid input type detection

Acceptance Criteria

✅ Implemented without using [::-1] or reverse()
✅ Handles various input scenarios
✅ Provides error handling for invalid inputs
✅ Passes all existing test cases

Performance Considerations

  • Linear time complexity O(n)
  • Minimal additional space usage
  • Efficient character swapping approach

Notes

  • Implementation uses manual character swapping
  • Maintains readability and performance

Changes Made

  • Implemented manual string reversal in src/string_reversal.py
  • Used two-pointer technique for in-place character swapping
  • Maintained comprehensive error handling
  • Preserved existing test coverage

Tests

  • Verify string reversal for various input types
  • Confirm error handling for invalid inputs
  • Ensure no built-in reversal methods are used
  • Check performance and time complexity

Signatures

Staking Key

BiYiK5ioyqd6c2pPvvjaSzLAhR8MMvBordhBnh9CordT: 2kzzh6Zv2eii53h8ZEzRWFXDwY6zRrygGTwr6ucXd5cqBFGNUtb4vNtt1jE8TRcStJuJAStiT2iwU184hnhDnjKzDshTHeNaTMjjFz6q5gReqbVyru3AiqPNE48CVeD7M9ussWPiyXbxsRQj2iCao1PnDtViciV3zLE2TnuhG5iiSSFsTF7SMKGwCbB5QN8Qpw1kxsxmz9YbNhcqW2hBwEWR5ABqakuuSHRaYpfe8wUJpD2CvMKwRQJsnh3rot1SazFbXDxNh9S6E9PgyU4MrnxWQDXC3QybFpZzApPHsjJZHCRQNbaCuDBDubH3SjQJSpKbg4ALejNRP9C9NWS6gDWediC8KWDg6LQd78LXEuowbuPeeVysugAp9zk

Public Key

7rnv8Gvvs8tbnnnddjozHRXqtmrMpW536PJRDxV4ua4t: 3TLtADV2dUmNYG2qhVnCfQBDroukx5vA6VXefLuEcPGBfvSnpbANtYujsmCm3ehQpbCg17kTeKNtQPnERLCNSx2a5J721H9gwhQgBmVwfdVzYiMKXRvFWrkQwKYQjxfbY1269tGyz5LM6nPdiEQmt1MVhoFHSTWyp1vPSByyaqAUisVT34uYdHgdeHEwcenqrhsSuEmcshKYXjh2R5DoqvTXbr3tqk8SbxNhit9xNNmGMyMkXaAo6Shh6ghuUudycvEqFihhPnoaTEnucQujmuBMhxkutQct4Ugmsj6SuBLJMjB5opRTgF8vopHLP3zZU1ntVBJdrMR7PQq2s2mtmNqNf6a86PFk34eEq2LzUXXbvYhZJnFGQJMfye

@momstrosity momstrosity changed the title [WIP] Implement String Reversal Function in Python Implement Manual String Reversal Function Without Built-in Methods May 22, 2025
@momstrosity momstrosity marked this pull request as ready for review May 22, 2025 17:17
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