Skip to content

Conversation

@testtesting123987654
Copy link

@testtesting123987654 testtesting123987654 commented May 27, 2025

Implement Manual String Reversal Function

Description

Task

Create a function that takes in a string and returns the reverse of the string

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:

  • Reverse a given string without using built-in slice notation or reverse() method
  • Handle various input scenarios
  • Provide robust error checking

Changes Made

Implementation Details

  • Created reverse_string() function in src/string_utils.py
  • Used a two-pointer approach for manual string reversal
  • Implemented type checking and error handling

Key Implementation Approach

  • Convert input string to a list of characters
  • Use left and right pointers to swap characters
  • Swap characters in-place until pointers meet
  • Convert back to string

Acceptance Criteria

✅ Function takes a string as input
✅ Returns the reversed string
✅ Handles empty strings
✅ Supports unicode and special characters
✅ Raises TypeError for non-string inputs
✅ Implemented without using slice notation or reverse()

Testing

  • Comprehensive test suite created in tests/test_string_utils.py
  • Covers multiple scenarios:
    • Basic string reversal
    • Empty string
    • Single character
    • Strings with spaces
    • Special characters
    • Unicode characters
    • Invalid input types

Test Results

  • All 7 test cases passed
  • 100% test coverage for the function

Performance Considerations

  • O(n) time complexity
  • O(n) space complexity
  • In-place character swapping minimizes memory overhead

Potential Improvements

  • Could add more comprehensive input validation if needed
  • Potentially optimize for extremely large strings

Changes Made

  • Implemented manual string reversal function
  • Added comprehensive type checking
  • Created test suite to validate function behavior
  • Ensured no use of built-in reversal methods

Tests

  • Verify basic string reversal
  • Check empty string handling
  • Test single character strings
  • Validate special character reversal
  • Ensure unicode character support
  • Confirm error handling for invalid inputs

Signatures

Staking Key

dummy_staking_key: dummy_staking_signature

Public Key

dummy_pub_key: dummy_public_signature

@testtesting123987654 testtesting123987654 changed the title [WIP] Implement String Reversal Function Implement Manual String Reversal Function May 27, 2025
@testtesting123987654 testtesting123987654 marked this pull request as ready for review May 27, 2025 01:24
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