Skip to content

Conversation

@momstrosity
Copy link

@momstrosity momstrosity commented May 21, 2025

Implement Efficient String Reversal Function with Manual Reversal Approach

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

String Reversal Function Implementation

Changes Made

  • Implemented a manual string reversal function in src/string_reversal.py
  • Created comprehensive test suite in tests/test_string_reversal.py

Implementation Details

  • Reversal Approach:
    • Used a two-pointer technique to reverse the string
    • Converts string to a list of characters
    • Manually swaps characters from both ends of the list
    • Converts back to a string using ''.join()

Acceptance Criteria Fulfillment

  1. ✅ Takes a string input and returns its reverse

    • Implemented two-pointer swap method
    • Works with strings of any length
  2. ✅ Handles empty strings

    • Explicitly checks for empty string and returns empty string
    • Test case included to verify empty string handling
  3. ✅ Preserves spaces and special characters

    • Reversal method maintains original character order
    • Comprehensive test cases cover various character types
  4. ✅ Implemented without using [::-1] or reverse()

    • Manual implementation using character swapping
    • No built-in reversal methods used

Testing Approach

  • Implemented 7 test cases covering:
    • Basic string reversal
    • Empty string
    • Single character strings
    • Strings with spaces
    • Strings with special characters
    • Unicode character support
    • Invalid input type handling

Performance Considerations

  • Time Complexity: O(n)
  • Space Complexity: O(n)
  • Uses in-place swapping for efficient reversal

Additional Notes

  • Includes robust type checking
  • Raises TypeError for non-string inputs
  • Handles various edge cases comprehensively

Test Results

  • All 7 test cases passed successfully
  • Full coverage of specified requirements
  • No external dependencies used

Changes Made

  • Implemented manual string reversal function in src/string_reversal.py
  • Created comprehensive test suite in tests/test_string_reversal.py
  • Added type checking and error handling
  • Implemented two-pointer reversal approach

Tests

  • Verify basic string reversal works correctly
  • Confirm empty string handling
  • Test single character string reversal
  • Validate preservation of spaces and special characters
  • Check unicode character support
  • Ensure type checking prevents invalid inputs

Signatures

Staking Key

BiYiK5ioyqd6c2pPvvjaSzLAhR8MMvBordhBnh9CordT: 2kzzh6Zv2eii53h8ZEzRWFXDwY6zRrygGTwr6ucXd5cqBFGNUtb4vNtt1jE8TRcStJuJAStiT2iwU184hnhDnjKzDshTHeNaTMjjFz6q5gReqbVyru3AiqPNE48CVeD7M9ussWPiyXbxsRQj2iCao1PnDtViciV3zLE2TnuhG5iiSSFsTF7SMKGwCbB5QN8Qpw1kxsxmz9YbNhcqW2hBwEWR5ABqakuuSHRaYpfe8wUJpD2CvMKwRQJsnh3rot1SazFbXDxNh9S6E9PgyU4MrnxWQDXC3QybFpZzApPHsjJZHCRQNbaCuDBDubH3SjQJSpKbg4ALejNRP9C9NWS6gDWediC8KWDg6LQd78LXEuowbuPeeVysugAp9zk

Public Key

7rnv8Gvvs8tbnnnddjozHRXqtmrMpW536PJRDxV4ua4t: 3TLtADV2dUmNYG2qhVnCfQBDroukx5vA6VXefLuEcPGBfvSnpbANtYujsmCm3ehQpbCg17kTeKNtQPnERLCNSx2a5J721H9gwhQgBmVwfdVzYiMKXRvFWrkQwKYQjxfbY1269tGyz5LM6nPdiEQmt1MVhoFHSTWyp1vPSByyaqAUisVT34uYdHgdeHEwcenqrhsSuEmcshKYXjh2R5DoqvTXbr3tqk8SbxNhit9xNNmGMyMkXaAo6Shh6ghuUudycvEqFihhPnoaTEnucQujmuBMhxkutQct4Ugmsj6SuBLJMjB5opRTgF8vopHLP3zZU1ntVBJdrMR7PQq2s2mtmNqNf6a86PFk34eEq2LzUXXbvYhZJnFGQJMfye

@momstrosity momstrosity changed the title [WIP] Implement String Reversal Function in Python Implement Efficient String Reversal Function with Manual Reversal Approach May 21, 2025
@momstrosity momstrosity marked this pull request as ready for review May 21, 2025 13:08
@laura-abro
Copy link

String Reversal Function Implementation

Description

Implementation of a string reversal function with comprehensive unit tests

Recommendation

APPROVE

Reasons:

  • Correct implementation of string reversal
  • Comprehensive test coverage including edge cases
  • Proper error handling for invalid inputs
  • Tests are well-designed and cover multiple scenarios

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: 2p1de65d8NiUfBxxgoniwTQzFCsMkZn2qNFZsGAmeueMTMZgbqbGdrMCNcrJAuo5xVmCBg6Y5EPeiQtrtvonfBPXVh8q9HLbpji1U5UcCZmL2UgeBVLbNs6h8BrRaP2G1Q8EKS63knrpKxEBMrQuLggqCB7aoqv5ehNGAEe5WTyz1EjrVy2YuDJ4Qb9TT7S6oMAWQuJjFHXbACk7rb2kN2VLfDVxyUWZ9FeyrcefCsjirn4c6Za6uz1hb3RPdPJPWrcsUpt6Xc5Nd5uJArzmmjXuKaXLW3RoEWyPqzKWRYaR8Hx7ien1Z1BRZegDEZjFUKshLkL42kaZthBPM48JFsFkGmZKeNNpQfjkLP4kLQyAHF4iiFosBLcKCvX4Y

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: jbcD4FnWSojrD992rd8E6UJhKY7MTk1RcWceZvjeFBoAmUoG1vGUjxGQBtKtQqeALagsTJq6kYazveE8xYuEB4ZS5CS1BsvnFJjGubBZG1fw6NghKLkT84aemHf1F43W8ipNQQRwmwbkpqP2WYbUMcBhst8kn4mZRCgLhpRypjp6wPuRUasWXVp5NYicz8jojV4TsAL2pDEaYWJfcJLYZCMgjGKZMZKWH1Xxz6cUDdY27qZCDYWhPhwrKxyu7nVpdQZrNgR9oobTpGbFBBPNma684v6apwwwwbteLNbS8sfJpH7CJV2DhpbrfRTXUy2z1RSJWmJTTGEpJkMDkGEwZnCKHJeTd4ZKbLwVEsVeBPaJzFt6mAfQT6g76pv76

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