An array is said to be `hollow` if it contains `3` or more `0`s in the middle that are preceded and followed by the same number of non-zero elements. Furthermore, all the zeroes in the array must be in the middle of the array. 

Write a function named `isHollow`/`is_hollow`/`IsHollow` that accepts an integer array and returns `true` if it is a hollow array,else `false`.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def is_hollow(x):
	

Solutions:
def is_hollow(x):
	while x and x[0] != 0 and (x[-1] != 0):
		x = x[1:-1]
	return len(x) > 2 and set(x) == {0}


from itertools import groupby
from operator import not_

def is_hollow(a):
	b = [(x, [*y]) for (x, y) in groupby(a, key=not_)]
	return len(b) == 1 and b[0][0] and (len(b[0][1]) > 2) or (len(b) == 3 and [x for (x, _) in b] == [0, 1, 0] and (len(b[1][1]) > 2) and (len(b[0][1]) == len(b[2][1])))


from itertools import groupby

def is_hollow(x):
	xs = [(key, sum((1 for _ in grp))) for (key, grp) in groupby(x)]
	mid = len(xs) // 2
	limit = len(xs) - (len(xs) > 1)
	return any((i == mid < limit for (i, (x, cnt)) in enumerate(xs) if x == 0 and cnt >= 3)) and sum((x == 0 for (x, _) in xs)) == 1


def is_hollow(x):
	return len(x) > 2 and (x[0] and x[-1] and is_hollow(x[1:-1]) or set(x) == {0})


from re import match

def is_hollow(x):
	return bool(match('(x*)[0]{3,}\\1$', ''.join(('x' if v else '0' for v in x))))


def is_hollow(x):
	if len(x) < 3:
		return False
	z = 0
	for (i, (a, b)) in enumerate(zip(x, x[::-1])):
		if i > len(x) // 2:
			return z >= 2
		if (a == 0) != (b == 0):
			return False
		if a != 0 and z > 0:
			return False
		if a == 0:
			z += 1
		elif z > 0:
			return False


def is_hollow(A):
	while A and A[0] * A[-1] != 0:
		A = A[1:-1]
	return 2 < A.count(0) and set(A) == {0}


import re

def is_hollow(x):
	return True if re.match('^(1*)0{3,}\\1$', ''.join(('0' if i == 0 else '1' for i in x))) else False


def is_hollow(x):
	i = j = len(x) // 2
	while i > 0 and x[i - 1] == 0:
		i -= 1
	while j < len(x) and x[j] == 0:
		j += 1
	prefix = x[:i]
	suffix = x[j:]
	return not (j - i < 3 or 0 in prefix + suffix or len(prefix) != len(suffix))