Reverse a String (Easy)
Good evening! Here's our prompt for today.
You may see this problem at Microsoft, Cisco, Salesforce, Twitter, Godaddy, Oracle, Ebay, Splunk, Hashicorp, Servicetitan, Sumo Logic, Seagate, Zuora, and Qualtrics.
Hey there, welcome to the challenges portion of the AlgoDaily technical interview course! Over the next few days, you'll get some hands-on experience with the essential data structures and algorithms that will help you nail your interview, and land your dream software engineering job.
The only way to get better at solving these problems is to power through a few.
We covered the best ways to prepare in this lesson, in this one, and here. Be sure to visit those if you need some more guidance. Otherwise, let's jump into it.
Reverse a String
Let's reverse a string!

We'll usually start with a simple prompt, as you would in a regular technical interview. Like most, this one will be intentionally open-ended.
Prompt
Can you write a function that reverses an inputted string without using the built-in Array#reverse
method?
Let's look at some examples. So, calling:
reverseString("jake")
should return "ekaj"
.
reverseString("reverseastring")
should return "gnirtsaesrever"
.

Constraints
- Do not use the built-in
#reverse() method
or[::-1]
if Python - Ideal solution would run in
O(n)
time complexity andO(1)
space complexity
xxxxxxxxxx
var assert = require('assert');
function reverseString(str) {
// reverse str
return str;
}
try {
assert.equal(
reverseString('njnschnjkdasn j32 uida'),
'adiu 23j nsadkjnhcsnjn'
);
console.log(
'PASSED: ' +
"`reverseString('njnschnjkdasn j32 uida')` should return `'adiu 23j nsadkjnhcsnjn'`"
);
} catch (err) {
console.log(err);
}
try {
assert.equal(reverseString('timbuktu12'), '21utkubmit');
console.log(
'PASSED: ' + "`reverseString('timbuktu12')` should return `'21utkubmit'`"
);