Majority element | Divide and Conquer | Leetcode 169

  Рет қаралды 4,387

Deep Coding

Deep Coding

3 жыл бұрын

Python code
github.com/deeepcoding/youtub...
Explanation Pic
github.com/deeepcoding/youtub...
Problem Link
leetcode.com/problems/majorit...

Пікірлер: 4
@rafik1968
@rafik1968 Күн бұрын
def divide_conquer(nums,l,r) : if l == r: return (nums[l], 1) mid = (l + r) // 2 f = divide_conquer(nums,l,mid) s = divide_conquer(nums,mid+1,r) ## not the same majority substract the extra if f[0] != s[0] : if f[1] > s[1] : return (f[0],f[1]-s[1]) else : return (s[0],s[1]-f[1]) else : return (f[0],s[1]+f[1]) # print(divide_conquer(nums)) n = len(nums) return divide_conquer(nums,0,n-1)[0] Here is the code in python based on your explanation and it works. Thanks
@harrybi5847
@harrybi5847 3 жыл бұрын
Thankyou! Your recursion tree is very clear for me understand this algo!
@pravinpoudel1307
@pravinpoudel1307 Жыл бұрын
why can't we make a hash map and update the count in the hash map with a key which is coming in each iteration of array !! and iterate the hash to find the max occiring element?
@gursimransingh7018
@gursimransingh7018 5 ай бұрын
wtf was that where is code . why you wrote leetcode 169
What's going on with Windows Laptops?
10:30
Marques Brownlee
Рет қаралды 2,7 МЛН
Why "pop-up" restaurants are everywhere now
6:05
Vox
Рет қаралды 298 М.
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 12 МЛН
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 8 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 598 М.
Why Taiwan isn’t “Taiwan” at the Olympics
15:41
Phil Edwards
Рет қаралды 273 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 402 М.
Why Labour is (Sort of) Nationalising Energy
8:13
TLDR News
Рет қаралды 98 М.
How To Pass Technical Interviews When You Suck At LeetCode
14:32
Klavye İle Trafik Işığını Yönetmek #shorts
0:18
Osman Kabadayı
Рет қаралды 8 МЛН
Yanlışlıkla Telefonumu Parçaladım!😱
0:18
Safak Novruz
Рет қаралды 817 М.
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 65 МЛН
My iPhone 15 pro max 😱🫣😂
0:21
Nadir Show
Рет қаралды 1,8 МЛН