```
class Solution:
# @param board, a list of lists of 1 length string
# @param word, a string
# @return a boolean
def exist(self, board, word):
X = len(board)
Y = len(board[0])
cor_add = lambda x, y: (x[0]+y[0], x[1]+y[1])
neighbor = [(1,0), (-1,0), (0,1), (0,-1)]
stack = []
for i in xrange(X):
for j in xrange(Y):
if board[i][j] == word[0]:
stack.append(([(i, j)], word[1:]))
while not stack == []:
s = stack.pop()
c, w = s
if w == '':
return True
l = c[-1]
ln = [cor_add(l, n) for n in neighbor]
for x in ln:
if not (x[0]>=0 and x[0]<X and x[1]>=0 and x[1]<Y):
continue
if not (board[x[0]][x[1]] == w[0]):
continue
if x not in c:
stack.append((c + [x], w[1:]))
return False
```

I ran test cases of:

==== 1, 2, 3

examples given in the problem

==== 4

["aaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaab"]

"baaaaaaaaaaaaaaaaaa...

==== 5

["elxllvxegzmvgnhrypvagxrgwktiqnyuavfnsfsbgewnrferubrcykjwveenrfhtamhvtzwafspzxvqtwkxwwgttkzgdenzhcgcvhyxosonrjgmhsjeo", ...

"oajgdkcokvfpdaslnmomrpgwitwdoku"

On my MBP:

$ time python word-search.py

True

True

False

True

True

```
11514 function calls in 0.087 seconds
```

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)

```
1 0.000 0.000 0.087 0.087 <string>:1(<module>)
1 0.001 0.001 0.087 0.087 word-search.py:31(main)
5 0.079 0.016 0.086 0.017 word-search.py:5(exist)
6988 0.006 0.000 0.006 0.000 word-search.py:8(<lambda>)
10 0.000 0.000 0.000 0.000 {len}
2757 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1751 0.000 0.000 0.000 0.000 {method 'pop' of 'list' objects}
```

real 0m0.116s

user 0m0.101s

sys 0m0.013s

I don't know how much the time limit is, but I think you need to give python at least 100ms per test case.