Skip to content

Commit 5287fcd

Browse files
authored
Merge pull request #341 from sir-gon/feature/luck_balance
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
2 parents eff1f7b + 0d98a70 commit 5287fcd

File tree

1 file changed

+9
-9
lines changed
  • exercises/hackerrank/interview_preparation_kit/greedy_algorithms

1 file changed

+9
-9
lines changed

exercises/hackerrank/interview_preparation_kit/greedy_algorithms/luck_balance.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type Contest struct {
1313
}
1414

1515
func luckBalance(k int32, contests [][]int32) int32 {
16-
var important_contests = []Contest{}
17-
var nonimportant_contests = []Contest{}
16+
var importantContests = []Contest{}
17+
var nonImportantContests = []Contest{}
1818

1919
for _, contest := range contests {
2020
var contest = Contest{
@@ -24,14 +24,14 @@ func luckBalance(k int32, contests [][]int32) int32 {
2424

2525
if contest.important == 1 {
2626

27-
important_contests = append(important_contests, contest)
27+
importantContests = append(importantContests, contest)
2828
} else {
29-
nonimportant_contests = append(nonimportant_contests, contest)
29+
nonImportantContests = append(nonImportantContests, contest)
3030
}
3131
}
3232

3333
slices.SortFunc(
34-
important_contests,
34+
importantContests,
3535
func(a, b Contest) int {
3636
return cmp.Or(
3737
-cmp.Compare(a.important, b.important),
@@ -40,18 +40,18 @@ func luckBalance(k int32, contests [][]int32) int32 {
4040
})
4141

4242
var total int32 = 0
43-
var size = int32(len(important_contests))
43+
var size = int32(len(importantContests))
4444
var cut = min(k, int32(size))
4545

4646
for i := 0; int32(i) < cut; i++ {
47-
total += important_contests[i].luck
47+
total += importantContests[i].luck
4848
}
4949

5050
for i := cut; i < size; i++ {
51-
total -= important_contests[i].luck
51+
total -= importantContests[i].luck
5252
}
5353

54-
for _, contest := range nonimportant_contests {
54+
for _, contest := range nonImportantContests {
5555
total += contest.luck
5656
}
5757

0 commit comments

Comments
 (0)