這題我覺得相對有挑戰性,我是用遞迴解
```
def ArrayChallenge(arr):
def isSum(target, l):
if target == 0:
return True
if not l:
return False
l += [0]
return any([isSum(target - l[i], (l[:i] + l[i+1:])[:-1]) for i in range(len(l)-1)])
MAX = max(arr)
arr.pop(arr.index(MAX))
return 'true' if isSum(MAX, arr) else 'false'
# keep this function call here
print(ArrayChallenge(input()))
```
Check valid brackets
Leetcode 經典題,檢測括弧是否合法
Leetcode 的有各種括弧(用 stack):https://leetcode.com/problems/valid-parentheses/
Coderbyte 只有小括弧(用一個 int 就可以):https://coderbyte.com/information/Bracket Matcher
Maximum stock profit
Leetcode 經典題,給你一串股價趨勢,計算最大獲利
```
def ArrayChallenge(arr):
profit = 0
current_min = float('inf')
for i in arr:
current_min = min(i, current_min)
profit = max(profit, i - current_min)
return profit if profit != 0 else -1
# keep this function call here
print(ArrayChallenge(input()))
```
給你一堆節點,判斷是否可以構成一個合法的二元樹
考對 tree 的熟練度
```
def ArrayChallenge(strArr):
d = {}
for i in strArr:
a = d.get(i[1], {'isChild': True, 'childCnt': 0})
a['isChild'] = True
d[i[1]] = a
b = d.get(i[3], {'isChild': False, 'childCnt': 0})
b['childCnt'] += 1
if b['childCnt'] > 2:
return 'false'
d[i[3]] = b
return 'true' if sum([not d[i]['isChild'] for i in d]) == 1 else 'false'
# keep this function call here
print(ArrayChallenge(input()))
```
SQL
```
SELECT * FROM maintable_B7CWJ
WHERE LastName = 'Smith' OR FirstName = 'Robert'
ORDER BY Age
```