## Task

Given a string, add the fewest number of characters possible from the front or back to make it a palindrome.

## Example

For the input `cdcab`, the output should be `bacdcab`

## Input/Output

Input is a string consisting of lowercase latin letters with length 3 <= str.length <= 10

The output is a palindrome string satisfying the task.

For s = `ab` either solution (`aba` or `bab`) will be accepted.

Difficulty: EASY

Starter code:
def build_palindrome(s):
	

Solutions:
def build_palindrome(s):
	for n in range(len(s), -1, -1):
		if s[:n] == s[:n][::-1]:
			return s[n:][::-1] + s
		if s[-n:] == s[-n:][::-1]:
			return s + s[:-n][::-1]


def build_palindrome(s):
	a = s[1:][::-1] + s
	temp = s
	for i in range(len(s) + 1):
		temp = s[::-1][:i] + s
		if temp == temp[::-1] and len(temp) < len(a):
			a = temp
	b = s + s[::-1]
	temp = s
	for i in range(len(s) + 1):
		temp = s + s[::-1][i:]
		if temp == temp[::-1] and len(temp) < len(b):
			b = temp
	if len(a) > len(b):
		return b
	else:
		return a


def is_palindrome(s):
	return s == s[::-1]

def left_strip_palindrome(s):
	for i in range(len(s) - 1):
		if is_palindrome(s[i:]):
			return s[:i]
	return None

def right_strip_palindrome(s):
	for i in range(-1, 1 - len(s), -1):
		if is_palindrome(s[:i]):
			return s[i:]

def build_palindrome(s):
	lsp = left_strip_palindrome(s)
	rsp = right_strip_palindrome(s)
	if lsp is not None:
		lsp_ans = s + lsp[::-1]
		if rsp is not None:
			rsp_ans = rsp[::-1] + s
			return min((lsp_ans, rsp_ans), key=len)
		return lsp_ans
	if rsp is not None:
		rsp_ans = rsp[::-1] + s
		return rsp_ans
	return s[1:][::-1] + s


def is_palindrome(s):
	return s == s[::-1]

def build_palindrome(s):
	for i in range(len(s)):
		x = s + s[:i][::-1]
		if is_palindrome(x):
			return x
		x = s[-i or len(s):][::-1] + s
		if is_palindrome(x):
			return x


def build_palindrome(s, i=0):

	def bp(s):
		a = s + s[:i][::-1]
		if a == a[::-1]:
			return a
	return bp(s) or bp(s[::-1]) or build_palindrome(s, i + 1)


def build_palindrome(s):
	if list(s) == list(s)[::-1]:
		return s
	for i in range(1, len(s)):
		if s[i:] == s[i:][::-1]:
			break
	endAdd = s + s[0:i][::-1]
	for i in range(1, len(s)):
		if s[:-i] == s[:-i][::-1]:
			break
	frontAdd = s[-i:][::-1] + s
	print(endAdd)
	print(frontAdd)
	if len(list(endAdd)) <= len(list(frontAdd)):
		return endAdd
	else:
		return frontAdd


def is_palindrome(word: str) -> bool:
	return word[::-1] == word

def build_left_palindrome(word: str) -> str:
	length = len(word)
	while not is_palindrome(word[:length]):
		length -= 1
	return word[length:][::-1] + word

def build_right_palindrome(word: str) -> str:
	return build_left_palindrome(word[::-1])[::-1]

def build_palindrome(word: str) -> str:
	return sorted([build_left_palindrome(word), build_right_palindrome(word)], key=len)[0]


def build_palindrome(s):
	l = len(s)
	left = next((l - i for i in range(l, 0, -1) if s[:i] == s[i - 1::-1]))
	right = next((l - i for i in range(l, 0, -1) if s[-i:] == s[:-i - 1:-1] or left == l - i))
	return s[:-left - 1:-1] + s if left <= right else s + s[right - 1::-1]


def build_palindrome(s):
	rev = s[::-1]
	for i in range(len(s)):
		if s[i:] == s[i:][::-1]:
			return s + s[:i][::-1]
		if rev[i:] == rev[i:][::-1]:
			return rev[:i] + s