
Problem
Solution
Submissions
If String is a Rotation of Another
Certification: Intermediate Level
Accuracy: 0%
Submissions: 0
Points: 10
Write a C# program to check if a given string is a palindrome without using any built-in string reversal functions like Reverse(), or any LINQ methods. A palindrome is a word, phrase, or sequence that reads the same backward as forward. For this problem, consider only alphanumeric characters and ignore case sensitivity.
Example 1
- Input: str = "racecar"
- Output: true
- Explanation:
- Convert the string to lowercase: "racecar".
- Compare characters from both ends: 'r' == 'r' (positions 0 and 6).
- Move inward: 'a' == 'a' (positions 1 and 5).
- Continue: 'c' == 'c' (positions 2 and 4).
- Reach the middle character 'e' (position 3).
- All comparisons match, so "racecar" is a palindrome.
- Convert the string to lowercase: "racecar".
Example 2
- Input: str = "hello"
- Output: false
- Explanation:
- Convert the string to lowercase: "hello".
- Compare characters from both ends: 'h' != 'o' (positions 0 and 4).
- Since the first comparison fails, "hello" is not a palindrome.
- No need to check further as we already found a mismatch.
- Convert the string to lowercase: "hello".
Constraints
- 1 ≤ str.length ≤ 10^4
- str contains only alphanumeric characters and spaces
- You are not allowed to use built-in string reversal functions or LINQ
- Case should be ignored (treat 'A' and 'a' as the same)
- Time Complexity: O(n)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
| Lang | Status | Date | Code |
|---|---|---|---|
| You do not have any submissions for this problem. | |||
| User | Lang | Status | Date | Code |
|---|---|---|---|---|
| No submissions found. | ||||
Solution Hints
- Use two pointers approach - one starting from the beginning and one from the end
- Convert characters to lowercase for case-insensitive comparison
- Skip non-alphanumeric characters if present
- Compare characters at both pointers and move them toward each other
- If any comparison fails, return false immediately
- If all comparisons pass, return true