id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

norm.krumpe@muohio.edu recursionarrays > isPalindrome
prev  |  next  |  chance

We will say an array is a palindrome if the list of elements is the same forward and backward. For example, {3, 7, 1, 7, 3} is a palindrome, but {2, 4, 2, 2, 4} is not a palindrome. Write a recursive method that returns true if the array is a palindrome. You should solve this recursively (no loops). You will need a recursive helper method that takes an array and an index as parameters. Note: You will need to write a recursive helper method. Advice: Work toward the middle of the array. You can stop checking when you get close enough to the middle of the array. But if you haven't reached the middle yet, then check the current element with its "partner" in the other half of the array. If they match, then let recursion handle the rest of the array. Alternatively: You could start near the middle of the array and work "outward" toward the end.


isPalindrome([3, 7, 1, 7, 3]) → true
isPalindrome([2, 4, 2, 2, 4]) → false
isPalindrome([5, 5]) → true

...Save, Compile, Run (ctrl-enter)

boolean isPalindrome(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 300

Copyright Nick Parlante 2017 - privacy