101 Logo
onenoughtone

Problem Statement

Message Encryption

You're working for a cybersecurity company that needs to develop a simple encryption system for sending messages between field agents. The encryption method needs to be straightforward enough that agents can perform it manually if needed, but effective enough to prevent casual observers from reading the messages.

Your team decides to implement a basic string reversal algorithm as the first layer of encryption. While not cryptographically secure on its own, it will be combined with other methods later.

Your task is to write a function that takes a string as input and returns the string reversed. For example, "hello" would become "olleh".

Examples

Example 1:

Input: "hello"
Output: "olleh"
Explanation: The characters in "hello" are reversed to form "olleh".

Example 2:

Input: "Secure Message"
Output: "egasseM eruceS"
Explanation: Each character in "Secure Message" is reversed, including the space.

Example 3:

Input: "Agent 007"
Output: "700 tnegA"
Explanation: Numbers and special characters are also reversed.

Constraints

  • The input string length is between 1 and 10^5 characters.
  • The string contains printable ASCII characters.
  • You must reverse the string in-place with O(1) extra memory (for some languages).
  • For languages where strings are immutable, use minimal extra space.

Problem Breakdown

To solve this problem, we need to:

  1. Understand how to access and manipulate individual characters in a string.
  2. Consider the differences between mutable and immutable string implementations in different languages.
  3. Think about how to swap characters efficiently without using additional data structures.
  4. Be mindful of the string's length and handle edge cases appropriately.
ProblemSolutionCode
101 Logo
onenoughtone