Skip to content

Conversation

@momstrosity
Copy link

@momstrosity momstrosity commented May 20, 2025

Implement Manual String Reversal Function without Slice Notation

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:

  • Reverse a string without using slice notation [::-1]
  • Reverse a string without using the built-in reverse() method
  • Handle various input scenarios and edge cases

Implementation Details

Source File: src/string_reversal.py

  • Implemented a two-pointer technique for string reversal
  • Converted string to a list of characters for manual manipulation
  • Added robust type checking to ensure only string inputs are accepted
  • Used in-place swapping to efficiently reverse the string

Key Algorithm

  • Convert input string to a list of characters
  • Use two pointers (left and right) to swap characters
  • Move pointers towards the center until they meet
  • Convert the modified list back to a string

Testing Approach

Test File: tests/test_string_reversal.py

Comprehensive test coverage includes:

  • Normal string reversal
  • Empty string handling
  • Single character string
  • Strings with spaces
  • Strings with special characters
  • Non-string input type checking

Acceptance Criteria Met

  • ✅ Reverses strings manually
  • ✅ No use of slice notation
  • ✅ No use of built-in reverse() method
  • ✅ Handles edge cases
  • ✅ Provides clear error handling
  • ✅ Passes all test cases

Performance Characteristics

  • Time Complexity: O(n)
  • Space Complexity: O(n)

Notes

  • Implementation provides a clean, manual approach to string reversal
  • Maintains flexibility and readability
  • Robust error handling for invalid inputs

Changes Made

  • Implemented manual two-pointer string reversal algorithm
  • Added comprehensive type checking
  • Ensured no use of slice notation or reverse()
  • Maintained existing test coverage

Tests

  • Verified normal string reversal
  • Confirmed empty string handling
  • Checked single character reversal
  • Tested strings with spaces and special characters
  • Validated error handling for non-string inputs

Signatures

Staking Key

AEghvdqmRtc3fjKXfNTMJJ6WshksgWuJ9YBExgsZu8cN: 2mAFiJayd24JTTaLSY4nwEXRim6oRmaFZHiaoV9q7HZkMNaJR2W5FHpuJb2td91Kj8SsUtoCjVoCsgbax4AZCDM4XRU1SXQzygKJ5rV1AdB3dpYpLcKijRNNkyr2CCBC51gzjE6UwNGZn6SpbM5DqrcLhygefP7GJaBDHkjSooFXzprfzxePQGc2P4C6YGgudD8gbTd5U4YwTjAnd98AGqj2a5fbYFLRjymPYdkGp1GbJ2LSPaXZr1cjfFYoJjAyrZVVgwta6D1L8Mau4hxGeMLyHC1Fr2f4okKY1Jc511LdGYRagM4kWjihkG28sCtafSebPp1qb3vzQhLEjNyq88483CRkqmWAqU5zwvaiiLKuxcz8Qnrtg75qrE2D3aa4cPSPVtVCNRgYXQT5e5KX7kwvuhatGX9bd3i

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: 2LCpcg5LrCa3yi1xFbNfz5qJw6PsRFTn8pR3YEcUzA4EHQP3ThuxskF2p7uuVQVZ2E5zNXpYj6QUtwoWk1ycNPE5aFDNDnPdUjzu44JZJSQ51yYJq4ENEvQQzubosDdWDLpwQN48V74mUWfTUs3KyeDvMGv9CFYSzbhHRKdLtkQ8Xtf6GTMmHkjjRSQs9qZZEqcrfde7VC3Jm3vKqVW2NJDuQCw8dB8BtaXt1VBDS1i8HUKgbLjqo7Z2c5PzB8icRwUZwTyYyPvu2fLKjFXEkVwoQ9CUqzsTcrDpKQcmWS5qdQQzQnyDofjDjNbjHVL5bPn3AFcqqSZpvG3Hp7svP76oAxe1EzpKa2wnKaheJME1aC6G7Qub9bhdPw3dxBee4Gg292Dz6zcX6PVsJSXUHkuM14TWTixFN3eC

@momstrosity momstrosity changed the title [WIP] Implement String Reversal Function in Python Implement Manual String Reversal Function without Slice Notation May 20, 2025
@momstrosity momstrosity marked this pull request as ready for review May 20, 2025 20:03
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