about | help | code help+videos | done | prefs |
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) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 300
Copyright Nick Parlante 2017 - privacy