Skip to content

Commit c6682ae

Browse files
committed
2600. K Items With the Maximum Sum
1 parent b98b147 commit c6682ae

File tree

1 file changed

+24
-0
lines changed
  • K Items With the Maximum Sum

1 file changed

+24
-0
lines changed

K Items With the Maximum Sum/kata.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package kata
2+
3+
func kItemsWithMaximumSum(numOnes int, numZeros int, numNegOnes int, k int) int {
4+
var sum int
5+
if numOnes >= k {
6+
sum += 1 * k
7+
return sum
8+
} else if numOnes > 0 {
9+
sum += numOnes * 1
10+
k = k - numOnes
11+
}
12+
if numZeros >= k {
13+
return sum
14+
} else if numZeros > 0 {
15+
k = k - numZeros
16+
}
17+
if numNegOnes >= k {
18+
sum += -1 * k
19+
return sum
20+
} else if numNegOnes > 0 {
21+
sum += -1 * numNegOnes
22+
}
23+
return sum
24+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy