Quick Quiz on Recursion with Strings!

This quiz will test your understanding of recursion with strings.

1

The task is to reverse the string provided.

public static String reverseString(String myStr) {
  // Base case
  if (myStr.isEmpty()) {
    return myStr;
  }

  // Recursive case
  else {
    return reverseString(myStr.substring(1)) + myStr.charAt(0);
  }
}

What should the base case of the above mentioned code be?

A)

myStr == null

B)

myStr.isEmpty()

C)

myStr.length < 1

Question 1 of 20 attempted

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.