Skip to content

Conversation

@laura-abro
Copy link
Owner

Implement Manual String Reversal Function

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 manual string reversal function that meets the specified requirements for reversing a string without using built-in reversal methods.

Changes Made

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

Implementation Details

Source Code (src/string_reversal.py)

  • Uses a two-pointer approach to reverse the string
  • Converts string to a list for in-place character swapping
  • Implements type checking to handle invalid inputs
  • Preserves all original characters, including spaces and special characters

Reversal Algorithm

  • Time Complexity: O(n)
  • Space Complexity: O(n)
  • Technique:
    1. Convert string to list of characters
    2. Use two pointers (left and right)
    3. Swap characters from both ends moving inwards
    4. Stop when pointers meet in the middle

Acceptance Criteria

  • Takes a string input
  • Returns the reversed string
  • Preserves spaces and special characters
  • Implemented without using string[::-1] or reverse()
  • Handles edge cases (empty string, single character)
  • Provides type checking for invalid inputs

Testing

  • Added 7 test cases covering:
    • Basic string reversal
    • Empty string
    • Single character string
    • Strings with spaces
    • Strings with punctuation
    • Mixed character types
    • Invalid input handling

Test Results

  • All 7 tests passed successfully
  • 100% coverage of expected functionality

Notes

  • Manually implemented reversal to meet specific requirements
  • Maintains original string character integrity
  • Provides clear error handling for invalid inputs

Changes Made

  • Created manual string reversal implementation
  • Added type checking for input validation
  • Implemented two-pointer reversal technique
  • Comprehensive test suite for various input scenarios

Tests

  • Test basic string reversal
  • Test empty string reversal
  • Test single character string
  • Test string with spaces
  • Test string with punctuation
  • Test mixed character types
  • Test invalid input handling

Signatures

Staking Key

5EmgCQSgPD79JWPQ6KMAV35kUNxasNQymeWuQXfJPmVk: w8jeQ3RLHuW7yNbDTkamX1ckZXgtxTqRE4Mz4rX84swjdtqCqEhAiNz4fiPDdQVC63FHLJDtuYvG7MDtp63zZbpivocUyEXzhVoZafwf5osSG4CGatBLEexdvjNxgX2C5LWWMmSDd2DHuhsP6N7CCjVewdoNUfv9KgHzeC5xwDWL9ZXKPTdUZxBxs9JrcZ1jr8Tx17X9EK7Rvsda2LkXMypqyNUXR4c2rFU7RpiK9MHrC9usJWtakfxeDyENGv3rRHopm4SVpmPqkb1tc8PD6cQ9Z1PMcyYyFHtkixSUzFhYHj18LP7L5tPwHu2htszD7zVs4YuoGespBasNxanG7bmDSGchzTosDo8mDKfLF6v81nZB6cdsWhaHULXPg9jpsAyYZ5KJuuVQQ9krArgxv8Dg9nmNMXEc

Public Key

8U4eXGpP28X2i8wDEDxwGUdSdPuz7xuMBvpFuVyPDNKz: 2cUr667L6S3rJT5ZCgjwnXWdsWHGetAb1J4MBdkCujvFB5G7o8KJLyzL7gdvC77dM24LF68TQcCBJYhLkhVPGQBVVaZRjvo65J4b99VtVj7Y1tFjC2E1hPXoeW5Ad9XiB4ckwT1Me4JzyfHphafAcTnsrshbonpsyXSgJ8DLtKY3MRjGscYpFL2QkdFjHuTe5hwHgo9HNiuwCjpXEov45W8uGGHr5aiVnrqGWWWpcdWUi49Unxjz3MqVnCqhNWo1UhvxudN5dVr6rv3jPqV2392WRVKLq6ADY8RauUHSHL6ZmPF9BJ3cx97gYwu5q5ZCanBXeX8bEZrw4ApF714TfSszHCqMRgcmanXoCgpfSFBbUB7NRGPQ6CDkeH4DRvu1gtXNWAJ1w6Nv86p2443Z5iRdRwu58yH7r

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