Why is FAANG Asking Such an EASY Coding Question? | Running Sum of 1d Array - Leetcode 1480

preview_player
Показать описание
dynamic programming, leetcode, coding interview question, data structures, data structures and algorithms, faang
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

"First, I'm gonna import pandas"...

comedyclub
Автор

Part of the test is naming conventions. naming your temp variables something like "currentSum" instead of "s" is important.

WifeWantsAWizard
Автор

def running_sum(nums):
sum = 0
return [(sum := sum + val) for val in nums]

SirBearingtonSupporter
Автор

Are you serious, on phone screens I ask "in any programming language, determine the length of a string" and approximately 1/50 resume-screened candidates say anything remotely sensible lol.

donwald
Автор

If you're using a language with a scan function it can be even simpler. E.g. in Scala
val nums = List(1, 2, 3, 4)
nums.scan(0)(_ + _).tail

hughjwoods
Автор

Wouldn't you want to yield the sum at each iteration to make it "running"?

TreeLuvBurdpu
Автор

You can flex and even do it in O(1) space if you wanna be fancy

abdulamite
Автор

If the numbers will always be evenly spaced you could use the Gauss method to find the sum of any sub array of arbitrary length, no need to to keep a running total.

evancourtney
Автор

nums = [1, 2, 3, 4]

Result = [0]*len(nums)
Result[0] = 1
for i in range(1, len(nums)):
Result[i] = Result[i-1] + nums[i]

print(Result)

donfeto
Автор

Can you recommend great online platform to learn data structure and algorithms to get at equipt to answer these interview questions?

helensirani
Автор

Why a list and not initialize the array with the same size as the input array that you want to cumulative sum over

datadecks
Автор

What is the name of the software he uses as a blackboard?

tm-luk
Автор

where do i find this kind of questions?

jeffmejia
Автор

just run it on the GPU split the array and put in multi threaded addition on CUDA

tennicktenstyl
Автор

from itertools import accumulate

result = list(accumulate(arr)) # 😂

suic
Автор

What if I want to modify nums instead of creating a new array?

eclipsesword
Автор

Iterate from index 1 update index I with index I + index i-1

vishalsrivastava
Автор

Why wouldn't you allocated the sums[] to have as many items as nums? Now you are dynamically growing it while adding the sums...

AllanSavolainen
Автор

Everything is easy if you practiced first.

frstchan