easyStringsPattern: Basic String Operations
String Reversal Check Solution
Problem Statement
Given two strings, determine if the second string is a reversal of the first string or not.
Examples
Example 1:
Input:hello, olleh
Output:true
Explanation: The string 'olleh' is a reversal of 'hello'.
Example 2:
Input:abcde, edcba
Output:true
Explanation: The string 'edcba' is a reversal of 'abcde'.
Constraints
- Length of each string ≤ 100
- Only lowercase English letters are used
- No white spaces or special characters are allowed in the strings
Time: O(n) Space: O(1)
A more efficient approach is to use two pointers, one starting at the beginning of the first string and one at the end of the second string, and then compare characters while moving the pointers towards the center, achieving a time complexity of O(n).
Run, Test & Submit Code
Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.
Solve on Interactive WorkspaceTested Solutions
No solution code is currently loaded.
Complete this code in the workspace editor.
