Published on

Codesignal - checkPalindrome solution


Solution one:

Looping through the array from last to first.

def checkPalindrome(inputString):
    r = ""

    for i in range(len(inputString)-1, -1, -1):
        r += inputString[i]

    return inputString == r

Solution two:

Using Python's default syntax.

def checkPalindrome(inputString):
    return inputString == inputString[::-1]

Solution three:

A JavaScript solution.

function checkPalindrome(inputString) {
  return inputString == inputString.split('').reverse().join('')

Solution four:

An optimal solution because it's just looping through half of the array.

def checkPalindrome(inputString):
    for i in range(len(inputString) // 2):
        if inputString[i] != inputString[-i - 1]:
            return False
    return True