palindrome hacker rank challenge

Solutions on MaxInterview for palindrome hacker rank challenge by the best coders in the world

showing results for - "palindrome hacker rank challenge"
Drew
29 Apr 2017
1function isPalindrome(str){
2  if(str === str.split('').reverse().join('')){
3    return true
4  }
5  return false
6}
7
8function palindromeIndex(str) {
9    if(str.length < 1) return -1
10    
11    let i = 0
12    let j = str.length - 1
13    
14    while(i < j && str[i] == str[j]){
15        i += 1
16        j -= 1
17    }
18    
19    if(isPalindrome(str.slice(0, i) + str.slice(i+1, str.length))){
20      return i
21    } 
22    if(isPalindrome(str.slice(0, j) + str.slice(j+1, str.length))){
23      return j
24    } 
25    return -1
26}