Skip to content

Conversation

@laura-abro
Copy link
Owner

Implement Manual String Reversal Function with Comprehensive Testing

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 manually reverses a string without using built-in methods like [::-1] or reverse().

Changes Made

  • Created reverse_string() function in src/string_reversal.py
  • Implemented a two-pointer manual string reversal algorithm
  • Added comprehensive test suite in tests/test_string_reversal.py

Implementation Details

Function Implementation

  • Uses a two-pointer technique to reverse the string
  • Converts string to a list of characters
  • Swaps characters from both ends moving towards the center
  • Preserves all characters, including spaces and special characters
  • Includes type checking to ensure only string inputs are accepted

Key Implementation Features

  • Manual reversal without built-in methods
  • O(n) time complexity
  • O(n) space complexity
  • Handles various input scenarios

Acceptance Criteria

✅ Takes a string input
✅ Returns the reversed string
✅ Preserves spaces and special characters
✅ Implemented without using [::-1] or reverse()
✅ Includes robust error handling
✅ Comprehensive test coverage

Testing Approach

  • Created 7 test cases covering:
    1. Basic string reversal
    2. Empty string
    3. Single character
    4. Strings with spaces
    5. Strings with special characters
    6. Mixed character strings
    7. Invalid input handling

Test Results

  • All 7 test cases passed successfully
  • 100% test coverage
  • Verified correct string reversal for various input types

Considerations

  • The implementation uses additional space to convert to a list
  • Linear time complexity ensures efficient performance for most use cases

Changes Made

  • Created manual string reversal implementation in src/string_reversal.py
  • Used two-pointer technique to reverse string
  • Added type checking for input validation
  • Implemented comprehensive test cases in tests/test_string_reversal.py

Tests

  • Test basic string reversal
  • Test empty string reversal
  • Test single character reversal
  • Test string with spaces
  • Test string with special characters
  • Test mixed character string
  • Test invalid input handling

Signatures

Staking Key

5EmgCQSgPD79JWPQ6KMAV35kUNxasNQymeWuQXfJPmVk: 2QFVYh4PorVWdd5ueZdUN4HRAYMXGWr2A88iG4KHNQgmHmJx4NaPuBCNp723EGzyir3kp21gcWGBZkVjNiC31fu2mW2iWhM7yLgNwXuefB5QghTVoRvpXKdMaGJ1MvP77piZPa1b27TKYdvNmEcWn83EHyE2Ay68x7BDTDXzULXUBK6K6hAFWmvWfB5uQo8BpUGejEqDBzvNF2EeskxMeB4Xg28nExTX7YoEF5pzyrA2QEKgxuBXWRLXirGozurKsWRDB85P1G8m9wmTAGud4YP3P7HXPFvyum376hB3baWSJDpYPDirYHNLu27r8hswi8xWBczFq5fRgNb7QWzQRXULDAt13TtQ25Kw5EhoYnEF6EUxk7odiPPSuk9LExZqfSik3Q8kr3bcEWuAhLC3jQ9Vi1C4mnBWnUFn

Public Key

8U4eXGpP28X2i8wDEDxwGUdSdPuz7xuMBvpFuVyPDNKz: 2NAWyAWCM1cHoL4qyN46Pqst2vprDQ8RTXEfbaXA8PKDkKYaMyzDA3WeriUBZdpLRAXPrQnayywF2ZZJJ5vvxqhuPqUpJpjRM5oyjTkB7f9UXy6TF6WzHxC7GLFzQdWC5GtcKLg9evDf57qMZVX22tSZLTfgW5F4UyiEZXyyR3gWK3uSTbpscEhdBAPfgeZ76ad2oKHsg72xfD8e2xPiP3t77kZ6bKMKcuv1fNZoDJcZP1iCMvpdssqQ7BmhzZQeTts8YEe6LHqSHhEgHe4DdH4JSwd6Q32QD5p1LGfNyBfUgF6ZVLzAxjKsfVCHkxH83XFAkYLizaWercScSpEo3uT8mikFp7RQgBY8v13s4spJ2tXzVa84EsDojn7YAsXz4mKrbiYZAYCaPC14EsUjpJkRFnfknMVnR3oz

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