
Problem
Solution
Submissions
Reverse a String
Certification: Basic Level
Accuracy: 100%
Submissions: 2
Points: 5
Write a JavaScript function to reverse a string. Implement built-in methods where the function should return a reversed string.
Example 1
- Input: s = "hello"
- Output: "olleh"
- Explanation:
- The original string is "hello" with characters h-e-l-l-o.
- Reversing the order gives us o-l-l-e-h.
- The reversed string is "olleh".
- The original string is "hello" with characters h-e-l-l-o.
Example 2
- Input: s = "JavaScript"
- Output: "tpircSavaJ"
- Explanation:
- The original string is "JavaScript" with 10 characters.
- Reversing character by character from end to beginning.
- The reversed string is "tpircSavaJ".
- The original string is "JavaScript" with 10 characters.
Constraints
- 0 ≤ s.length ≤ 10^4
- s consists of printable ASCII characters
- Time Complexity: O(n)
- Space Complexity: O(n)
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
- For built-in approach: convert string to array, use reverse() method, then join back
- Alternatively, build the reversed string by iterating from the last character
- Consider edge cases like empty strings