>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process  --myjinxin2015 said

# Description:
 Given a string `str` that contains some "(" or ")". Your task is to find the longest substring in `str`(all brackets in the substring are closed). The result is the length of the longest substring.

 For example:
 ```
 str = "()()("
 findLongest(str) === 4 
 "()()" is the longest substring
 ```
 
# Note:
 - All inputs are valid.
 - If no such substring found, return 0.
 - Please pay attention to the performance of code. ;-)
 - In the performance test(100000 brackets str x 100 testcases), the time consuming of each test case should be within 35ms. This means, your code should run as fast as a rocket ;-) 
 
# Some Examples
 ```
 findLongest("()") === 2
 findLongest("()(") === 2
 findLongest("()()") === 4
 findLongest("()()(") === 4
 findLongest("(()())") === 6
 findLongest("(()(())") === 6
 findLongest("())(()))") === 4
 findLongest("))((") === 0
 findLongest("") === 0
 ```

Difficulty: EASY
Starter code: def find_longest(st):
	

Solutions:
def find_longest(st):
	(res, pos) = (0, [0])
	for (i, b) in enumerate(st, 1):
		if b == '(':
			pos.append(i)
		else:
			try:
				pos.pop()
				res = max(res, i - pos[-1])
			except:
				pos.append(i)
	return res


def find_longest(s):
	(stack, m) = ([-1], 0)
	for (i, j) in enumerate(s):
		if j == '(':
			stack.append(i)
		else:
			stack.pop()
			if stack:
				m = max(m, i - stack[-1])
			else:
				stack.append(i)
	return m


def find_longest(st):
	(longest_run, stack) = (0, [-1])
	for (i, c) in enumerate(st):
		if c == ')':
			stack.pop()
			if stack:
				longest_run = max(longest_run, i - stack[-1])
				continue
		stack.append(i)
	return longest_run


def find_longest(st):
	stack = [-1]
	longest = 0
	for index in range(0, len(st)):
		if st[index] == '(':
			stack.append(index)
		else:
			stack.pop()
			if stack:
				longest = max(longest, index - stack[-1])
			else:
				stack.append(index)
	print(longest)
	return longest


def find_longest(st):
	n = len(st)
	lis = []
	lis.append(-1)
	result = 0
	for i in range(n):
		if st[i] == '(':
			lis.append(i)
		else:
			lis.pop()
			if len(lis) != 0:
				result = max(result, i - lis[len(lis) - 1])
			else:
				lis.append(i)
	return result


def find_longest(st):
	(stack, max_so_far) = ([-1], 0)
	for ind in range(len(st)):
		if st[ind] == '(':
			stack.append(ind)
		else:
			stack.pop()
			if len(stack) > 0:
				max_so_far = max(max_so_far, ind - stack[-1])
			else:
				stack.append(ind)
	return max_so_far


def find_longest(string):
	n = len(string)
	stk = []
	stk.append(-1)
	result = 0
	for i in range(n):
		if string[i] == '(':
			stk.append(i)
		else:
			stk.pop()
			if len(stk) != 0:
				result = max(result, i - stk[len(stk) - 1])
			else:
				stk.append(i)
	return result


from itertools import groupby

def find_longest(st):
	positions = []
	stack = []
	for (i, ch) in enumerate(st):
		if ch == '(':
			stack.append(i)
		elif stack:
			positions.append(stack.pop())
			positions.append(i)
	positions.sort()
	res = [a + 1 == b for (a, b) in zip(positions, positions[1:])]
	ans = [len(list(g)) + 1 for (k, g) in groupby(res)]
	return max(ans, default=0)


def find_longest(st):
	positions = []
	stack = []
	for (i, ch) in enumerate(st):
		if ch == '(':
			stack.append(i)
		elif stack:
			positions.append(stack.pop())
			positions.append(i)
	prev = float('-inf')
	cons = 0
	ans = 0
	for (i, p) in enumerate(sorted(positions)):
		if p == prev + 1:
			cons += 1
		else:
			ans = max(ans, cons)
			cons = 1
		prev = p
	return max(ans, cons)


import re

def find_longest(s):
	regex = '\\(a*\\)'
	while re.search(regex, s):
		s = re.sub(regex, lambda x: 'a' * len(x.group()), s)
	r = map(len, re.findall('a+', s))
	return max(r, default=0)