Subarray Sums Divisible by K - Leetcode 974 - Python

  Рет қаралды 11,747

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/subarra...
0:00 - Read the problem
0:30 - Drawing Explanation
14:30 - Coding Explanation
leetcode 974
#neetcode #leetcode #python

Пікірлер: 67
@joelnoronha6031
@joelnoronha6031 22 күн бұрын
I have a two technical interviews on Wednesday and Thursday. Hopefully I clear them and get the job🤞 Edit - Dint get selected for next round. I'll keep leetcoding until I get another job
@AdityaRaj-xm6oi
@AdityaRaj-xm6oi 22 күн бұрын
Good luck buddy
@chrischika7026
@chrischika7026 22 күн бұрын
goodluck, and comeback to this comment to tell us how you did.
@NeetCodeIO
@NeetCodeIO 22 күн бұрын
Good luck you got this!!!
@akakop
@akakop 22 күн бұрын
Hopefully I get this question
@varunagarwal1756
@varunagarwal1756 21 күн бұрын
You guys are getting interviews?
@akash-kumar737
@akash-kumar737 22 күн бұрын
Pattern is same as yesterday problem. Thanks man your explanation helped me solve this on my own.
@yang5843
@yang5843 22 күн бұрын
Thanks for uploading this, the issue I realized I was having with this problem was due to negative numbers being modded in Java
@maanas_sehgal
@maanas_sehgal 22 күн бұрын
Hey @Neetcode Can you please upload solutions for contests as well. It would be really helpful😊
@chaitanyasharma6270
@chaitanyasharma6270 21 күн бұрын
-1%5 is 4 in python but in other languages, java c#, javascript it is equal to -1. curr+=nums[i]; int key = curr % k; if(curr
@YashTech16
@YashTech16 21 күн бұрын
if sum is -5 and k = 5 then key is 0 but as curr < 0 key would be changed Hence one more condition required curr += nums[i]; int key = curr % k; if(curr < 0 && key != 0){ key += k; }
@ameydhimte_c5956
@ameydhimte_c5956 21 күн бұрын
@@YashTech16 key won't be zero buddy. How would you make a sum divisible by 0
@Antinormanisto
@Antinormanisto 21 күн бұрын
I understand how it's 4 Just some math that i hate: a = -1 // 5, how to do it? -1 / 5 = -0.2, round it to the floor. a = -1. -1 % 5(it's b, ok?) = -1(a) * 5(b) + x -1 % 5 = -5 + x. x is 4 because we need to find the x that will give the first number(-1) after plusing the x with the result -1(a) * 5(b) (-5) -1 = -5 + x 4 = x Sorry if I made a mistake, but I heard this solution how to solve mod(%) with negative numbers
@markuscwatson
@markuscwatson 21 күн бұрын
This works in typescript: `let rem = ((sum % k) + k) % k;`
@marcoaraujo9446
@marcoaraujo9446 21 күн бұрын
But with regard to this difference, do you know why? Why does python have a different result to java, shouldn't the operation be implemented in the same and be agnostic from programming language ?
@thomasmcnutt252
@thomasmcnutt252 19 күн бұрын
much easier to understand than the leetcode editorial! Nice job!
@MP-ny3ep
@MP-ny3ep 22 күн бұрын
Great explanation as always. Thank you
@fiascogamingchannel78
@fiascogamingchannel78 21 күн бұрын
pretty much got this thanks to yesterdays leetcode daily problem and by figuring out the pattern of how the occurence of multiple remainders are contributing in final ans
@nirmalgurjar8181
@nirmalgurjar8181 21 күн бұрын
For java programmers if remainder is -ve then just add k to it to make it positive same as python does and all will be right. if(rem < 0) rem = k + rem;
@EliasKibret
@EliasKibret 22 күн бұрын
Main Point : If two prefix sums have the same remainder when divided by 𝐾 ,the subarray between these two prefix sums is divisible by 𝐾
@fancypants6062
@fancypants6062 22 күн бұрын
this channel is so good
@AJK-a2j00k4
@AJK-a2j00k4 21 күн бұрын
Crazy intuition fr!
@sidreddy7030
@sidreddy7030 22 күн бұрын
Yayyy you’re finally back
@jensenzhang2452
@jensenzhang2452 22 күн бұрын
thank you neetcode!
@chien-yuyeh9386
@chien-yuyeh9386 22 күн бұрын
Nice!!😊
@DeathSugar
@DeathSugar 21 күн бұрын
For whoever stuck on "wrong" remainders for negative numbers - use Euclidean remainder instead of default % operator. It goes like (n % m + m) % m.
@nnkbrain
@nnkbrain 22 күн бұрын
Hey can you also solve the contest questions ❓
@saisurisetti6278
@saisurisetti6278 22 күн бұрын
Ok I’m too addicted to these videos.. I need to stop.. this is past my bed time lolz
@abid3801
@abid3801 18 күн бұрын
Bro, Your teaching is nice. It would be nicer if you took care of your accent. Please do
@pastori2672
@pastori2672 21 күн бұрын
woudlt an array actually have n! subarrays since your starting at every position and each time decrementing one so it would be like n * (n - 1) * (n - 2)... ?
@user-he4st2ro5h
@user-he4st2ro5h 21 күн бұрын
I didn't get it. In this particular case divisible doesn't mean evenly divisible, i.e. it doesn't have to be prefix_sum % k == 0?
@user-ns7tu5no1i
@user-ns7tu5no1i 21 күн бұрын
i always stuck on these kind of problems why i dont get a intution of solving them , I mean optimize solutions.
@zinnia993
@zinnia993 21 күн бұрын
Can you explain why (remainder < 0) remainder = k+remainder works?
@zweitekonto9654
@zweitekonto9654 21 күн бұрын
Read about modular arithmetic for negative numbers.
@tai-xinyu407
@tai-xinyu407 22 күн бұрын
Because of the problem yesterday, 523, I watched the video of 560, but I still feel a little confused about 523. Will you explain and upload it? Even make it into shorts would be helpful.
@Stopkaaaa
@Stopkaaaa 22 күн бұрын
He already did it kzfaq.info/get/bejne/hbGTpa-Xt5OcnXk.html
@gagandhand8907
@gagandhand8907 19 күн бұрын
For negative remainder, its not working.
@s8x.
@s8x. 22 күн бұрын
bro what’s ur routine like
@RACM27MD
@RACM27MD 21 күн бұрын
Hint: If you're not using python, don't forget to adjust the remainder to be a positive number in case the language you're using returns a negative remainder. if (remainder < 0) remainder += k;
@gagandhand8907
@gagandhand8907 19 күн бұрын
Will it work for negative remainder? For me its nor working.
@its_shivam_jha
@its_shivam_jha 13 күн бұрын
yaa it doesn't work for me too
@venusshili
@venusshili 22 күн бұрын
why we don't need check the remainder is positive?
@hesheid9159
@hesheid9159 22 күн бұрын
python take right remainder we dont need to check it
@yxchen6080
@yxchen6080 22 күн бұрын
@@hesheid9159 does it mean that the logic of this solution is only for python? In other language, we need to adjust the remainder to positive by ourself?
@zinnia993
@zinnia993 21 күн бұрын
@@yxchen6080 yes we need another check if remainder is negative
@stormShadow64
@stormShadow64 21 күн бұрын
I still don't understand it
@MehmetDemir-xi3yy
@MehmetDemir-xi3yy 22 күн бұрын
Bob ross reference
@user-qp5cw8sd4w
@user-qp5cw8sd4w 22 күн бұрын
first
@nikhil199029
@nikhil199029 21 күн бұрын
Am I stupid or this problem was hard? prolly I am stupid 😅
@sabukuna
@sabukuna 21 күн бұрын
its a big math gap. i couldnt do it either.
@vishruthpuli1664
@vishruthpuli1664 22 күн бұрын
Third
@upsidedownChad
@upsidedownChad 22 күн бұрын
Forth
@Antinormanisto
@Antinormanisto 21 күн бұрын
I'm like a monkey being taught P.s I didn't understand an explanation
Subarray Sum Equals K - Prefix Sums - Leetcode 560 - Python
15:19
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 111 М.
ОДИН ДЕНЬ ИЗ ДЕТСТВА❤️ #shorts
00:59
BATEK_OFFICIAL
Рет қаралды 7 МЛН
small vs big hoop #tiktok
00:12
Анастасия Тарасова
Рет қаралды 24 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 5 МЛН
Longest Palindrome - Leetcode 409 - Python
12:20
NeetCodeIO
Рет қаралды 10 М.
Continuous Subarray Sum - Leetcode 523 - Python
14:56
NeetCode
Рет қаралды 62 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 399 М.
Sum of Square Numbers - Leetcode 633 - Python
14:26
NeetCodeIO
Рет қаралды 11 М.
Subarray Sums Divisible by K | LeetCode 974 | C++, Java, Python
16:48
Knowledge Center
Рет қаралды 34 М.
Count Subarray sum Equals K | Brute - Better -Optimal
24:09
take U forward
Рет қаралды 220 М.
10 Nooby Mistakes Devs Often Make In Python
24:31
Indently
Рет қаралды 46 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 894 М.
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,3 МЛН
ИГРОВОВЫЙ НОУТ ASUS ЗА 57 тысяч
25:33
Ремонтяш
Рет қаралды 278 М.
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 4,4 МЛН
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 35 МЛН
💅🏻Айфон vs Андроид🤮
0:20
Бутылочка
Рет қаралды 740 М.