Skip to content

Commit

Permalink
Add some interview questions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljs1990 committed Jul 26, 2019
1 parent 41639d1 commit 55e3769
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions interview/code/partition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// https://www.techiedelight.com/partition-problem
package main

import (
"fmt"
)

func SumSlice(x []int) int {
xSum := 0

for _, v := range x {
xSum += v
}

return xSum
}

func solver(bucket, x []int, num int) bool {
if SumSlice(x) == (num / 2) {
return true
}

for idx := range bucket {
tmpBucket := []int{}
tmpBucket = append(tmpBucket, bucket[:idx]...)
tmpBucket = append(tmpBucket, bucket[idx+1:]...)

tmpX := []int{}
tmpX = append(x, bucket[idx])
if solver(tmpBucket, tmpX, num) {
return true
}
}

return false
}

func main() {
bucket := []int{7, 3, 1, 5, 4, 8}
fmt.Println(solver(bucket, []int{}, SumSlice(bucket)))
}
1 change: 1 addition & 0 deletions interview/code/rod_cutting.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// https://www.techiedelight.com/rot-cutting/
package main

import (
Expand Down

0 comments on commit 55e3769

Please sign in to comment.