Reverse the string and show the result.
Acceptance criteria
- 1.#out should show cba.
DSA Tutorial · Strings
These 10 tasks go with the Common String Problems chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Four patterns cover most string questions. Once you can see which one you are looking at, the code is short.” .
1.Reverse a wordexercise · easy · 10 min
Reverse the string and show the result.
Passes when: #out should show cba.
2.Test a palindromeexercise · easy · 10 min · practice plan
Report whether the cleaned word reads the same both ways.
Passes when: #out should show palindrome.
3.Check an anagramexercise · easy · 10 min · practice plan
Report whether two words use exactly the same letters.
Passes when: #out should show anagram.
4.First unique characterexercise · easy · 10 min · practice plan
Show the index of the first character that appears only once.
Passes when: #out should show index 0.
5.Longest unique runexercise · medium · 10 min · practice plan
Show the length of the longest run with no repeated character.
Passes when: #out should show run of 3.
6.Fix reverse used on a stringbug fix · easy · 8 min
reverse is an array method; a string has no such method to call.
Passes when: #out should show cba.
7.Fix the palindrome ignoring casebug fix · easy · 8 min · practice plan
Without lowering the case, the comparison fails on capitals.
Passes when: #out should show palindrome.
8.Fix the anagram missing the length checkbug fix · medium · 8 min · practice plan
Without comparing lengths, a prefix passes as an anagram.
Passes when: #out should show different.
9.Fix the unique scan over the mapbug fix · easy · 8 min · practice plan
Iterating the map loses the original order, so the index is wrong.
Passes when: #out should show index 4.
10.Fix the window start moving backwardsbug fix · easy · 8 min · practice plan
Without the guard, an old index can drag the window start back and overstate the run.
Passes when: #out should show run of 2.
Between them these tasks cover Palindromes, Anagrams and First unique.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.