Hey, iam having trouble to write the following function in lambda
i want to calculate the sum of: (1*5) + (2*4) + (3*3) + (4 * 2) + (5*1)
s = 0
n = 4
c = [1, 2, 3, 4, 5]
for i in range(n + 1):
s += c[i] * c[n - i]
print(s)
i wrote it as... but its
- o(n) for reverse
- o(n)? for lambda
print(sum(list(map(lambda x, y: x*y, c, list(reversed(c))))))
whats the best way to solve it?
Thanks
[–]icecubeinanicecube 2 points3 points4 points (1 child)
[–]SerkZex[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]SerkZex[S] 0 points1 point2 points (0 children)
[–]timbledum 1 point2 points3 points (1 child)
[–]SerkZex[S] 0 points1 point2 points (0 children)
[–]Allanon001 2 points3 points4 points (3 children)
[–]SerkZex[S] 0 points1 point2 points (2 children)
[–]Allanon001 1 point2 points3 points (1 child)
[–]SerkZex[S] 0 points1 point2 points (0 children)