Find Pivot Index - Leetcode 724 - Python

  Рет қаралды 52,088

NeetCode

NeetCode

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🐮 Support the channel: / neetcode
Twitter: / neetcode1
Discord: / discord
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 CODING SOLUTIONS: • Coding Interview Solut...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
🌲 TREE PLAYLIST: • Invert Binary Tree - D...
💡 GRAPH PLAYLIST: • Course Schedule - Grap...
💡 BACKTRACKING PLAYLIST: • Word Search - Backtrac...
💡 LINKED LIST PLAYLIST: • Reverse Linked List - ...
💡 BINARY SEARCH PLAYLIST: • Binary Search
📚 STACK PLAYLIST: • Stack Problems
Python Code: github.com/neetcode-gh/leetco...
Problem Link: leetcode.com/problems/find-pi...
0:00 - Read the problem
1:58 - Drawing Explanation
7:47 - Coding Explanation
leetcode 724
This question was identified as a Microsoft coding interview question from here: github.com/xizhengszhang/Leet...
#microsoft #interview #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.

Пікірлер: 47
@NeetCode
@NeetCode 2 жыл бұрын
Python Code: github.com/neetcode-gh/leetcode/blob/main/724-Find-Pivot-Index.py Java Code: github.com/ndesai15/coding-java/blob/master/src/com/coding/patterns/arrays/PivotIndexFinder.java (Provided by ndesai15 / Neel Desai)
@switchyard
@switchyard 2 жыл бұрын
If I ever get a job with fanng, it was 60% me working hard and 40% watching neetcode videos
@leeroymlg4692
@leeroymlg4692 Жыл бұрын
Did you end up scoring fanng job?
@doggo9757
@doggo9757 5 ай бұрын
Did you end up getting a job at FAANG?
@SuubUWU
@SuubUWU 3 ай бұрын
How’s that FANNG job?
@tamaranavamankumar3890
@tamaranavamankumar3890 2 жыл бұрын
The way u explaining the logic, we don't need to rewind back again...great 🎉and thankyou 👍
@ice_cube918
@ice_cube918 2 жыл бұрын
Very good explanations!
@gowthamjs23
@gowthamjs23 10 ай бұрын
Thanks for the video! I used the prefix sum methodology for this problem and it ran efficiently, sharing it in case if anyone finds it useful. def find_pivot_index(nums): prefix = [nums[0]] for i in range(1, len(nums)): prefix.append(nums[i] + prefix[-1]) for i in range(len(prefix)): if i == 0: left_sum = 0 else: left_sum = prefix[i-1] right_sum = prefix[-1] - prefix[i] if left_sum == right_sum: return i return -1
@samantasunanda
@samantasunanda Жыл бұрын
This is a beautiful explanation, thanks for sharing.
@bollinmore
@bollinmore 2 жыл бұрын
your explanation is easy to understand.
@littlecatboybuddy
@littlecatboybuddy Жыл бұрын
great explanation! thank you so much.
@tanmaydash803
@tanmaydash803 Жыл бұрын
Thanks buddy ....loves a ton for this vdo...totally worth it
@leventoz9530
@leventoz9530 11 ай бұрын
Use two arrays (of the same size as nums) to store the left sums (starting from the left) and the right sums (starting from the right) respectively. When calculating the "next" sum, you only need to add the value of the "previous" index's value with the partial sum already stored. (Next and previous's definitions depend on direction). Starting from the left, return the first index where the values are equal. Space: O(n), Time: O(n)
@sumanbyte
@sumanbyte Жыл бұрын
understood. thanks bro
@vineetjadhav1785
@vineetjadhav1785 11 ай бұрын
Hey Man Thanks for the smooth Explanantion ;))
@skmn07
@skmn07 2 жыл бұрын
@neetcode, what software and tools u use when explaing or hilighting text or drawing text
@annubaba7944
@annubaba7944 2 жыл бұрын
Hi brother ,Could you please choose some medium-hard level dp & bitmasking kind questions . Never had a better understanding by watching many other channel videos . Hope you're gonna do it. Thanks!
@stupidbutcurious6206
@stupidbutcurious6206 Жыл бұрын
Hi, can you please help me solve below questions please... The Question is:- Given an array of integers of size N, count all possible distinct triplets whose sum is exactly divisible by given integer K. for triplets i, j, k --> i
@MouseCodes
@MouseCodes 2 жыл бұрын
best explanation
@vinoddiwan5792
@vinoddiwan5792 Жыл бұрын
Logic was to focus on non zeros numbers . But the question focused on zeros. Good question
@AseshShrestha
@AseshShrestha 2 жыл бұрын
Thanks
@rohanaurangabadkar951
@rohanaurangabadkar951 3 ай бұрын
Just loved it!!!!
@sagardafle
@sagardafle 2 жыл бұрын
Thanks. Isn’t the intuition behind this solution same as sliding window algo? Where we avoid re-summing the numbers.
@jzvf_758
@jzvf_758 Жыл бұрын
amazing !
@GandharvaSMurthy
@GandharvaSMurthy 2 жыл бұрын
Will it be easy if iterate sum from left and right together and increment or decrement left or right based on my current sum of left or right ?
@hamoodhabibi7026
@hamoodhabibi7026 Жыл бұрын
problem is you don't know if there is a negative number in the future that'll destroy the sum and its not sorted
@leocoote1860
@leocoote1860 Жыл бұрын
Hi, I got a solution which is similar to yours, but instead of updating the right side by using the total left and the value of the pivot, Instead, I followed the same way we calculated the left side by taking the total right and taking away the pivot value as we move through the list (right_side -= i). Is there a reason your version is better, or are they equal roughly in speed? and Thanks for the Videos, they always help so much.
@DBagg-zz4ip
@DBagg-zz4ip Жыл бұрын
I did the same thing and it makes negligible difference. Maybe it saves a subtract operation but I doubt it's anything but a matter of practice/taste.
@shivaniverma4266
@shivaniverma4266 10 ай бұрын
happy teachers day
@jzvf_758
@jzvf_758 Жыл бұрын
can you do the running sum of array please. The code is pretty simple but i don't understand the for loop. would just love an explanation
@hamoodhabibi7026
@hamoodhabibi7026 Жыл бұрын
Not sure what you mean by running sum, but basically he has a for loop and for each index in the loop we have 2 variables leftSum and rightSUm. (that keeps track of the current sum at each iteration i. of the left side and right side of i) So at each index of the loop when both left and rightSum equal then we know that current index is our pivot
@jzvf_758
@jzvf_758 Жыл бұрын
@@hamoodhabibi7026 I mean that there is a leeetcode problem called running sum of array and I was asking him to explain it
@kaushikp918
@kaushikp918 Жыл бұрын
How do actually approach the problem in order to get an idea like that? also is this dynamic programming?
@AudreyGraceB
@AudreyGraceB Ай бұрын
Search for "sliding window"
@edwardteach2
@edwardteach2 Ай бұрын
You a Pivot God
@shariarnadim161
@shariarnadim161 7 күн бұрын
How about doing it using prefix sum
@inspiredomkar1239
@inspiredomkar1239 10 ай бұрын
class Solution { public int pivotIndex(int[] nums) { int totalSum = 0 ; for(int i = 0 ; i < nums.length ; i++){ totalSum = totalSum + nums[i]; } int leftSum = 0 ; for(int i = 0 ; i < nums.length ; i++){ totalSum = totalSum - nums[i]; if(leftSum == totalSum){ return i; } leftSum = leftSum + nums[i]; } return -1; } } Code using Java
@sarmadsohaib3032
@sarmadsohaib3032 Жыл бұрын
Hi, please test your code with test case [-1,-1,0,1,1,0]. Expected output is 5 but your code is returning -1.
@NeetCode
@NeetCode Жыл бұрын
Just tested, and my code returns 5
@sarmadsohaib3032
@sarmadsohaib3032 Жыл бұрын
@@NeetCode Oh Nice. I was mistaken. Thank you
@TheyCensorUsHere
@TheyCensorUsHere Жыл бұрын
I was going insane, walked the dog, came back, easily figured it out. *Sigh*
@juda550
@juda550 2 жыл бұрын
I love you
@LOLjerel
@LOLjerel Жыл бұрын
Bro this makes no sense lmao It's not even your fault.
@tawsifmahbub2440
@tawsifmahbub2440 Жыл бұрын
If you create C++videos you will be famous more than now
@xjsnjkil2070
@xjsnjkil2070 10 ай бұрын
nope, python is much more popular than C++
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,4 МЛН
Move Zeroes - Leetcode 283 - Python
8:15
NeetCode
Рет қаралды 67 М.
你们会选择哪一辆呢#short #angel #clown
00:20
Super Beauty team
Рет қаралды 17 МЛН
Survival skills: A great idea with duct tape #survival #lifehacks #camping
00:27
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27
Гараж 54
Рет қаралды 14 МЛН
Binary Search - Leetcode 704 - Python
9:40
NeetCode
Рет қаралды 135 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 273 М.
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 423 М.
Find Pivot Index | Explanation on WhiteBoard | Leetcode # 724
13:25
Binod Suman Academy
Рет қаралды 6 М.
Find the Difference of Two Arrays - Leetcode 2215 - Python
7:34
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 309 М.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 315 М.
Giant numbers
7:27
stuff | An abridged guide to interesting things
Рет қаралды 1,2 М.
LeetCode Find Pivot Index Solution Explained - Java
7:12
Nick White
Рет қаралды 20 М.
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 7 МЛН