Skip to content

Commit c43a59f

Browse files
committed
Non constructible change
1 parent 42c7350 commit c43a59f

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

Diff for: algoexpert/nonConstructibleChange/main.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"sort"
6+
)
7+
8+
func main() {
9+
coins := []int{1,1,1,1,1}
10+
fmt.Println("Non Constructable Change:", nonConstructibleChange(coins))
11+
12+
}
13+
14+
func nonConstructibleChange(coins []int) int {
15+
// Write your code here.
16+
sort.Ints(coins)
17+
amountOfChange := 0
18+
19+
for _, value := range coins {
20+
if value > amountOfChange {
21+
amountOfChange += 1
22+
}
23+
24+
amountOfChange += value
25+
}
26+
return amountOfChange
27+
}

Diff for: algoexpert/tournamentWinner/main.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
const HomeTeamWon = 1
8+
9+
func main(){
10+
competitions := [][]string{
11+
{"HTML", "C#"},
12+
{"C#", "Python"},
13+
{"Python", "HTML"},
14+
}
15+
results := []int{0,0,1}
16+
fmt.Println("Tournament Winner: O(n)", tournamentWinner(competitions, results))
17+
}
18+
func tournamentWinner(competitions [][]string, results []int) string {
19+
// Write your code here.
20+
currentWinner := ""
21+
arr := map[string]int{currentWinner: 0}
22+
23+
for idx, value := range competitions {
24+
homeTeam, awayTeam := value[0], value[1]
25+
winningTeam := awayTeam
26+
if results[idx] == HomeTeamWon {
27+
winningTeam = homeTeam
28+
}
29+
arr[winningTeam] += 3
30+
if arr[winningTeam] > arr[currentWinner] {
31+
currentWinner = winningTeam
32+
}
33+
}
34+
return currentWinner
35+
}
36+

Diff for: go.mod

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module random-golang-algorithms
22

33
go 1.17
4+
5+
require github.com/ekzhu/counter v0.0.0-20170810072917-1da58f92bf06
6+
7+
require github.com/orcaman/concurrent-map v1.0.0 // indirect

Diff for: go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/ekzhu/counter v0.0.0-20170810072917-1da58f92bf06 h1:yzw6ZUX+qLoMdOP76YWTHpmcajZeddoIUMxxOhMKNwo=
2+
github.com/ekzhu/counter v0.0.0-20170810072917-1da58f92bf06/go.mod h1:tmFCvk1+pNzbOQrguDXx8NRb/qGKAVCeOGTDtrGPUZY=
3+
github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HDbW65HOY=
4+
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=

0 commit comments

Comments
 (0)