Skip to content

Instantly share code, notes, and snippets.

@omas-public
Last active April 24, 2024 06:20
Show Gist options
  • Save omas-public/cfc04b3f7c98525df2e7ac97a11f9d19 to your computer and use it in GitHub Desktop.
Save omas-public/cfc04b3f7c98525df2e7ac97a11f9d19 to your computer and use it in GitHub Desktop.
# split_space = lambda s: [int(c) for c in s.split(' ')]
split_space = lambda s: list(map(int, s.split(' ')))
fn1 = lambda l, start, end: sum(l[start : end])
fn2 = lambda l, start, end: sum([n for index, n in enumerate(l) if start <= index <= end])
def fn4(l, start, end):
sum = 0
for index, value in enumerate(l):
if start <= index <= end:
sum += value
return sum
def f5(a, N, K):
fn1 = lambda l, start, end: sum(l[start : end])
acc = []
for i in range(N - K + 1):
acc.append(fn1(a, i, i + K))
return max(acc)
f6 = lambda a, N, K: max([fn1(a, i, i + K) for i in range(N - K + 1)])
f6(split_space('10 1 9 2 8 3 7 4 6 5'), split_space('10 4'))
[10, 1, 9, 2, 8, 3, 7, 4, 6, 5]
[0, 10, 11, 20, 22, 30, 33, 40, 44, 50, 55]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment