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 including empty strings, Unicode characters, and special characters
  • Provides robust error handling and type checking

Implementation Details

Source File: src/string_reversal.py

  • Created a manual string reversal algorithm using a two-pointer technique
  • Algorithm steps:
    1. Convert input string to a list of characters
    2. Use left and right pointers to swap characters
    3. Move pointers towards the center until they meet
    4. Convert back to a string

Key Algorithm Characteristics

  • Time Complexity: O(n)
  • Space Complexity: O(1) extra space
  • Handles all edge cases including:
    • Empty strings
    • Single character strings
    • Strings with spaces
    • Strings with special characters
    • Unicode strings

Testing Approach

  • Comprehensive test suite in tests/test_string_reversal.py
  • 7 test cases covering:
    1. Basic string reversal
    2. Empty string handling
    3. Single character strings
    4. Strings with spaces
    5. Strings with special characters
    6. Unicode character support
    7. Invalid input type detection

Acceptance Criteria Met

  • ✅ Implemented without using [::-1] or reverse()
  • ✅ Handles various input scenarios
  • ✅ Robust error handling
  • ✅ All tests passing

Notes

  • Uses manual character swapping approach
  • Maintains type safety with TypeError for non-string inputs

Changes Made

  • Implemented custom two-pointer string reversal algorithm in src/string_reversal.py
  • Added comprehensive error handling and type checking
  • Ensured compatibility with various string types and characters

Tests

  • Verify basic string reversal functionality
  • Test empty string handling
  • Validate single character string reversal
  • Check reversal with spaces and special characters
  • Confirm Unicode character support
  • Ensure proper error handling for invalid inputs

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 15:43
@laura-abro
Copy link

String Reversal Implementation

Description

Implemented a string reversal function with comprehensive test coverage

Recommendation

APPROVE

Reasons:

  • Complete implementation of string reversal function
  • Comprehensive test suite covering various input scenarios
  • Proper error handling for invalid inputs
  • In-place reversal algorithm with O(1) space complexity
  • All tests pass successfully

Unmet Requirements

All requirements met

Tests

Failed Tests

No failing tests

Missing Test Cases

No missing test cases identified

Action Items

No action items required

Signatures

Staking Key

AEghvdqmRtc3fjKXfNTMJJ6WshksgWuJ9YBExgsZu8cN: LTbA71SauJ7HFraWDNkUTH8Ymga1ALL7aG7odaiT7icTp62Z1DLYqKFsw36grx1iZycTVFDLaBvNhHFn1tWa3Ln8diTqJhyFH89X9eqsihGRdg77hvjDSRBo9YKZ1TWzjeDvWrtQABWosvQqSH47bsTjDBgcjixqHmaPzRj3JMMScZiPz8msoExUn6Q29NWxvuUXKHxvBDKUXmcbWjD6P9NxTYKyM5mW6aKJ773zm8Nrab2XzCzbVEjoEyfmcaVXs6xS9tXK9RrYvidfqaf8RvvsJQHK14RJ25acqnhbbPrH5TiqXfuYp3KTrc92ozje91BFVbjqkZtVyx5TCV79LFGnNcy5D6e8Ydxxf8rvm7y4CmuvFHgHbb22xFG9J

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: my389xiKsnoPnWq7jFuy5Jut42jV5Se7aH2K16JHGG3PYNCw1wGGcG5o5X2hELiA2k1NxFg32beuJuCKuycrHjXLe7QnvR7gqz6X71eicKMg8XMbazFhksuddBXuEVL9xnK4L6D66QGB7cjXGwLSpwRsxcqYEu5Z4ymTk7f82UCC4sVR97vpctK2DqwuV1ud3C93dwWvM47an3J92UVyr74zZLp4LUvXxghsBwjkVTxxvZGWsdBWXADzaGon8RAiMSYi3wBADbrqnfsBiFxe34ZZthArovRcG3tCQZTb15YKNqE541SgEN56Z5nLxV9ytBVWCPQLyC8WJu3k7N4XcP5jvd5neFX4uBUAEfjshPbLe74fttEEXw45EMqoa

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