Golang Binary Search
go\nfunc avoidFlood(rains []int) []int {\n\tavoid := make([]int, len(rains))\n\tlast := map[int]int{}\n\tvalid := make([]int, 0)\n\tfor i, v := range rains {\n\
```go\nfunc avoidFlood(rains []int) []int {\n\tavoid := make([]int, len(rains))\n\tlast := map[int]int{}\n\tvalid := make([]int, 0)\n\tfor i, v := range rains {\n\t\tif v > 0 {\n\t\t\tavoid[i] = -1\n\t\t\tif _, exist := last[v]; exist {\n\t\t\t\tif index := binarySearch(valid, last[v]); index < len(valid) {\n\t\t\t\t\tavoid[valid[index]] = v\n\t\t\t\t\tcopy(valid[index:], valid[index+1:])\n\t\t\t\t\tvalid = valid[:len(valid)-1]\n\t\t\t\t} else {\n\t\t\t\t\treturn []int{}\n\t\t\t\t}\n\t\t\t}\n\t\t\tlast[v] = i\n\t\t} else {\n\t\t\tvalid = append(valid, i)\n\t\t}\n\t}\n\tfor i, v := range avoid {\n\t\tif v == 0 {\n\t\t\tavoid[i] = 1\n\t\t}\n\t}\n\treturn avoid\n}\n\nfunc binarySearch(array []int, value int) int {\n\tl, r := 0, len(array)-1\n\tfor l <= r {\n\t\tm := (l+r)>>1\n\t\tif array[m] < value {\n\t\t\tl = m+1\n\t\t} else {\n\t\t\tr = m-1\n\t\t}\n\t}\n\treturn l\n}\n```
['Binary Tree', 'Go']