Find Missing Observations - Leetcode 2028 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
8:47 - Coding Explanation

leetcode 2028

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

“ you don’t want to blow your load to quickly “ 😂

Alexander-ztkz
Автор

You are the hero Gotham deserves!. Keep shining the Bat-signal for all of us aspiring software engineers!

Kaviarasu_NS
Автор

Sharing my idea,

rem = missing_sum % n
res = [missing_sum // n] * n
for i in range(rem):
res[i] += 1

sidharthprabhakaran
Автор

Knew how to solve . But couldn't figure out the sum part

aniket
Автор

Another greedy solution is to fill the array in the beginning with 1 then in each step we add up to 5 to the current element

mhmdshaaban
Автор

That's interesting, I didn't think of using the greedy approach. Mine was a bit different – instead of going for the biggest value, I picked the one closest to the average of the remaining sum!

galactus
Автор

I knew the comments would be there for me when he said that wild statement

BenjaminKodi-xsro
Автор

I cant keep up with neetcode pace or consistently of solving problems you truly admire me to solve everyday thanks 🙌

princeakhil
Автор

great work, keep doing, understandable, thank you so much neetcodeio.

karthi
Автор

Happy teachers day Navdeep. Yoir one of the finest teachers and have taught me a lot. Lots of love from India

anirudhta
Автор

why does missing_sum // n > 6 not pass test cases

andywu
Автор

leetcode is so weird, same exact solution, it's the most optimal according to the editorial as well but it consistently beats only 10% with 1s time for some reason, so i thought there would be a better one but nope somehow people with the same solution get ~150ms

pastori
Автор

There's a solution which is a bit more optimal - we know we need to put in each row at least missing_sum/n, so we initialize our return value with those and just add the rest of the sum one by one. it will take strictly less then O(n) to do so it's for sure gonna be more optimal.

DeathSugar
Автор

It is possible to solve it with O(1) time and space complexity, using the quotient and the rem approach. for eg:

q = missing//n
r = missing%n
res = [q+1] * r + [q]*(n-r)

tbh I did not come up with this solution entirely by myself, but it is something to consider

ayushmandash
Автор

I did it this way
if (requiredSum < 1 * n || requiredSum > 6 * n) return {};

while (n > 0) {
int observation = requiredSum / n;
ans.push_back(observation);
requiredSum -= observation;
n--;
}

If the requiredSum is not exactly divisible by n then the observations generated will be floating values initially (casted to integers) but after a certain iterations (could be the last one) the values generated will be integers/

ParodyCSEDept
Автор

Esay pezzzy today's one but when I saw the question I though it will be difficult

rupamsadhukhan
Автор

this code in C++, not passing the 3rd testcase[eg.]

Mohit-fehx
Автор

Thank you Bro, for (DDD) Daily Dose of Dopamine!

adilansari-hqge
Автор

a slightly more intuitive solution( a tad bit faster ) -

amount = mean*(len(rolls)+n) - sum(rolls)

if amount > 6*n or amount<n:
return []

f = amount//n
out = [f]*n
amount = amount - f*n
for i in range(0, amount):
out[i]+=1

return out


the logic is no two numbers in the output array( of n ) will vary more than 1, so create an array of equal quantities( the quotient ) and distribute the reminder( modulus ) across the output array

_PranavDesai
Автор

def missingRolls(self, rolls: List[int], mean: int, n: int) -> List[int]:

nSum = (mean)*(n + len(rolls)) - sum(rolls)

res = [nSum//n]*(n)
res[-1] += nSum%n

if nSum//n + nSum%n <= 6:
return res
return [ ]

for [1, 2, 3, 4] testcase expected and output both are empty list : [ ]. But it is WA. somebody help!!

Hari_.