forked from RezaSi/go-interview-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution-template.go
More file actions
43 lines (35 loc) · 1.23 KB
/
solution-template.go
File metadata and controls
43 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
)
func main() {
// Standard U.S. coin denominations in cents
denominations := []int{1, 5, 10, 25, 50}
// Test amounts
amounts := []int{87, 42, 99, 33, 7}
for _, amount := range amounts {
// Find minimum number of coins
minCoins := MinCoins(amount, denominations)
// Find coin combination
coinCombo := CoinCombination(amount, denominations)
// Print results
fmt.Printf("Amount: %d cents\n", amount)
fmt.Printf("Minimum coins needed: %d\n", minCoins)
fmt.Printf("Coin combination: %v\n", coinCombo)
fmt.Println("---------------------------")
}
}
// MinCoins returns the minimum number of coins needed to make the given amount.
// If the amount cannot be made with the given denominations, return -1.
func MinCoins(amount int, denominations []int) int {
// TODO: Implement this function
return 0
}
// CoinCombination returns a map with the specific combination of coins that gives
// the minimum number. The keys are coin denominations and values are the number of
// coins used for each denomination.
// If the amount cannot be made with the given denominations, return an empty map.
func CoinCombination(amount int, denominations []int) map[int]int {
// TODO: Implement this function
return nil
}