Skip to content

Conversation

@momstrosity
Copy link

@momstrosity momstrosity commented May 20, 2025

Implement Custom String Reversal Function Using Two-Pointer 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

Overview

This pull request implements a custom string reversal function that meets the following key requirements:

  • Reverse a string without using built-in slice notation or reverse() method
  • Handle various input scenarios
  • Provide robust type checking
  • Maintain efficient time and space complexity

Changes Made

  • Implemented reverse_string() function in src/string_reversal.py
  • Created comprehensive test suite in tests/test_string_reversal.py

Implementation Details

Function Approach

  • Uses a two-pointer swap method to reverse the string
  • Converts string to list for in-place character swapping
  • Manually swaps characters from both ends of the string

Key Implementation Features

  • O(n) time complexity
  • O(n) space complexity
  • Explicit type checking for input validation
  • Handles edge cases like:
    • Empty strings
    • Single character strings
    • Strings with spaces
    • Special characters
    • Unicode strings

Testing Approach

  • Implemented 7 distinct test cases covering:
    1. Basic string reversal
    2. Empty string handling
    3. Single character strings
    4. Strings with spaces
    5. Strings with special characters
    6. Unicode string support
    7. Invalid input type detection

Test Results

  • All 7 test cases passed successfully
  • 100% test coverage achieved
  • No external dependencies required

Acceptance Criteria Met

  • ✅ Implemented without using string[::-1] or reverse()
  • ✅ Handles various input scenarios
  • ✅ Provides type checking
  • ✅ Comprehensive test coverage

Notes

  • The implementation provides a manual, explicit approach to string reversal
  • Prioritizes readability and performance
  • Follows Python best practices for implementation

Potential Future Improvements

  • Consider alternative reversal algorithms if performance becomes a critical concern
  • Add more edge case tests if needed

Changes Made

  • Implemented custom two-pointer string reversal algorithm
  • Added comprehensive type checking
  • Created detailed docstring explaining function behavior
  • Ensured compatibility with various string types

Tests

  • Verified basic string reversal
  • Tested empty string handling
  • Checked single character strings
  • Validated strings with spaces
  • Tested special character strings
  • Verified unicode string support
  • Confirmed type checking for invalid inputs

Signatures

Staking Key

AEghvdqmRtc3fjKXfNTMJJ6WshksgWuJ9YBExgsZu8cN: 3YvfFJBEu6ovVtUw8dUagPBCeNTUaBK7yjmekw3yJhmfxWen9A2ETYxeVedDpL9MbAzy9NtYNg1BpXCuoRwASSqTrvR58QSFzBBKb2j78nbhCtoXeKzUEhpobgUq7dcjGVpENFJd33oFhDGeGG4MW9q9scW4V4ado4D34QYTLAwBhyfUx5TfhLUHqtaagW4rHLtBJu7RCHN1NLosj6FnZtNkxuSDBXcKg1jHvf8irWYCzkqbXouigtXAbuS1wXzKeaLRAeSJZh2ygyJmzQvjaHwv6n5yEN3Yx4Q27uxUBt1iU5ARdw3gEk7LACP3KyTiWVPf6iuEuVwx8Mfg3H3zquwxxrELuHxYgY4Fv8aZcSTSmN7YCNpMAyS62LYyzXxNTiWoAddYHN7cAsbZx52AmYuf3BWyyF2iQKji

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: 23f2nxV38WpuekGAShrenaiC8zXiPk3yKk6ZF3FontPBBYFFNtYpETjgYnBJPVwTUaBhDCEVHqQSFSNUUpMQbpv8Arr8NJzrZxUj8ta9P5PLzoXedjFMxKDK7MsNcPPDvnLytEFnJuDKyGcSJ8z8cwy8WMNrySQQZLjs8jtw76hGs3G2Y14DqfXM8RW6QR8S2FjWdnwr2NfEX9KXstB82fCh4jLqZMoHbVnZDdwUvKtALujbMbWLfPFeYKGiQqZWbpAKPEkBXKgoK15eKzU6h4VBDEYcL6b5x2ZpNKdHQBXXNXFnKo7kSngYcZ5YRfLuyHP7EfnoeWg8gc1PvQAZLQ3RcWLFhVtFEtJACZf2R5TzEP9asaAN6UWadt1KraqhsN83HxTLW3Vj6dwGeMPcciQbaiDry7nzyak

@momstrosity momstrosity changed the title [WIP] Implement String Reversal Function in Python Implement Custom String Reversal Function Using Two-Pointer Approach May 20, 2025
@momstrosity momstrosity marked this pull request as ready for review May 20, 2025 17:35
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