Skip to content

Commit 4ea58ac

Browse files
authored
Create determine-the-minimum-sum-of-a-k-avoiding-array.py
1 parent cc72124 commit 4ea58ac

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
# constructive algorithms, math
5+
class Solution(object):
6+
def minimumSum(self, n, k):
7+
"""
8+
:type n: int
9+
:type k: int
10+
:rtype: int
11+
"""
12+
def arithmetic_progression_sum(a, d, n):
13+
return (a+(a+(n-1)*d))*n//2
14+
15+
a = min(k//2, n)
16+
b = n-a
17+
return arithmetic_progression_sum(1, 1, a)+arithmetic_progression_sum(k, 1, b)

0 commit comments

Comments
 (0)