post_href
stringlengths
57
213
python_solutions
stringlengths
71
22.3k
slug
stringlengths
3
77
post_title
stringlengths
1
100
user
stringlengths
3
29
upvotes
int64
-20
1.2k
views
int64
0
60.9k
problem_title
stringlengths
3
77
number
int64
1
2.48k
acceptance
float64
0.14
0.91
difficulty
stringclasses
3 values
__index_level_0__
int64
0
34k
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756737/Simple-and-Clean-python-code
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: def fut(a,b): ret = 0 for i in range(len(a)): if a[i] != b[i]: ret += 1 return ret res = [] for q in queries: for d in dictionary: ...
words-within-two-edits-of-dictionary
Simple and Clean python code
w7Pratham
0
9
words within two edits of dictionary
2,452
0.603
Medium
33,600
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756735/Python-Solution
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: ans = [] s = set() def isequal(a,b,x): c = 0 i = 0 n = len(a) while i < n: if a[i] != b[i]: c += 1 ...
words-within-two-edits-of-dictionary
Python Solution
a_dityamishra
0
7
words within two edits of dictionary
2,452
0.603
Medium
33,601
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756715/Python3-Brute-Force-Solution
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: res = [] for word0 in queries: for word1 in dictionary: diff = 0 for t in range(len(word0)): if word0[t] != word1[t]: ...
words-within-two-edits-of-dictionary
Python3 Brute Force Solution
xxHRxx
0
4
words within two edits of dictionary
2,452
0.603
Medium
33,602
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756662/Python3-set-of-all-acceptable-words
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: d=set(dictionary) for w in dictionary: for i in range(len(w)): w1=w[:i]+'*'+w[i+1:] d.add(w1) for j in range(i,len(w)): w2=w...
words-within-two-edits-of-dictionary
Python3, set of all acceptable words
Silvia42
0
3
words within two edits of dictionary
2,452
0.603
Medium
33,603
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756646/PythonStraight-forward-code
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: output = [] count = 0 for word_queries in queries: for word_dictionary in dictionary: count = 0 for i in range(len(word_queries)): i...
words-within-two-edits-of-dictionary
【Python】Straight forward code ✅
gordonkwok
0
8
words within two edits of dictionary
2,452
0.603
Medium
33,604
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756522/Python-Easy-to-Understand-With-Explanation
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: def count(s, t): ans = 0 for i in range(len(s)): if s[i] != t[i]: ans += 1 if ans > 2: return False ...
words-within-two-edits-of-dictionary
[Python] Easy to Understand With Explanation
neil_teng
0
15
words within two edits of dictionary
2,452
0.603
Medium
33,605
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756513/Python3-or-Brute-Force
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: n,m=len(queries),len(dictionary) ans=[] for q in queries: for d in dictionary: cnt=0 i=0 while i<len(q): if q[i]!=d[...
words-within-two-edits-of-dictionary
[Python3] | Brute Force
swapnilsingh421
0
7
words within two edits of dictionary
2,452
0.603
Medium
33,606
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756457/Python-or-Easy-or
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: n = len(queries[0]) ans = [] for i in range(len(queries)): for j in range(len(dictionary)): count = 0 for k in range(n): ...
words-within-two-edits-of-dictionary
Python | Easy |
LittleMonster23
0
24
words within two edits of dictionary
2,452
0.603
Medium
33,607
https://leetcode.com/problems/destroy-sequential-targets/discuss/2756374/Python-or-Greedy-or-Group-or-Example
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: # example: nums = [3,7,8,1,1,5], space = 2 groups = defaultdict(list) for num in nums: groups[num % space].append(num) # print(groups) # defaultdict(<class 'list'>, {1: [3, 7, 1, 1, 5], 0: [...
destroy-sequential-targets
Python | Greedy | Group | Example
yzhao156
3
122
destroy sequential targets
2,453
0.373
Medium
33,608
https://leetcode.com/problems/destroy-sequential-targets/discuss/2794087/Python-(Simple-Maths)
class Solution: def destroyTargets(self, nums, space): dict1 = defaultdict(int) for i in nums: dict1[i%space] += 1 max_val = max(dict1.values()) return min([i for i in nums if dict1[i%space] == max_val])
destroy-sequential-targets
Python (Simple Maths)
rnotappl
1
5
destroy sequential targets
2,453
0.373
Medium
33,609
https://leetcode.com/problems/destroy-sequential-targets/discuss/2844702/Python3-Commented-and-Concise-Solution-Modulo-and-HashMap
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: # get a dict of modulos modulo_dict = dict() # go through the array and compute the modulo and their counter for idx, num in enumerate(nums): # compute the modulo modi = num % spac...
destroy-sequential-targets
[Python3] - Commented and Concise Solution - Modulo and HashMap
Lucew
0
1
destroy sequential targets
2,453
0.373
Medium
33,610
https://leetcode.com/problems/destroy-sequential-targets/discuss/2766934/One-pass-no-sorting-59-speed
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: d = dict() for n in nums: rem = n % space if rem in d: if n < d[rem][1]: d[rem][1] = n d[rem][0] -= 1 else: d[rem] = [...
destroy-sequential-targets
One pass, no sorting, 59% speed
EvgenySH
0
6
destroy sequential targets
2,453
0.373
Medium
33,611
https://leetcode.com/problems/destroy-sequential-targets/discuss/2760145/Python-or-Three-Lines-or-Mod-Counter-wexplanation
class Solution: def destroyTargets(self, xs: List[int], space: int) -> int: class_freqs = Counter(x % space for x in xs) max_count = max (class_freqs.values()) return min(x for x in xs if class_freqs [x % space] == max_count)
destroy-sequential-targets
Python | Three Lines | Mod Counter w/explanation
on_danse_encore_on_rit_encore
0
11
destroy sequential targets
2,453
0.373
Medium
33,612
https://leetcode.com/problems/destroy-sequential-targets/discuss/2757190/Python3-modulo
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: freq = Counter() mp = defaultdict(lambda : inf) for x in nums: k = x % space freq[k] += 1 mp[k] = min(mp[k], x) m = max(freq.values()) return min(mp[k] for k, v...
destroy-sequential-targets
[Python3] modulo
ye15
0
9
destroy sequential targets
2,453
0.373
Medium
33,613
https://leetcode.com/problems/destroy-sequential-targets/discuss/2756967/Python-Answer-Group-Numbers-by-Modulo-Space-into-Dict
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: #1,3,5,7,9,... #3, 5, 7, 9 #8, 10, #nums = [3,7,8,1,1,5], space = 2 groups = defaultdict(int) val = defaultdict(list) for n in nums: ...
destroy-sequential-targets
[Python Answer🤫🐍🐍🐍] Group Numbers by Modulo Space into Dict
xmky
0
9
destroy sequential targets
2,453
0.373
Medium
33,614
https://leetcode.com/problems/destroy-sequential-targets/discuss/2756811/Python3-Easy-Remainder-Solution-O(N)
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: nums.sort() dicts = defaultdict(int) for element in nums: dicts[element % space] += 1 target = max(dicts.values()) for element in nums: ...
destroy-sequential-targets
Python3 Easy Remainder Solution O(N)
xxHRxx
0
4
destroy sequential targets
2,453
0.373
Medium
33,615
https://leetcode.com/problems/destroy-sequential-targets/discuss/2756559/Group-nums-by-mod-space
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: numsByMod = defaultdict(list) for num in nums: numsByMod[num % space].append(num) maxLength = 0 for group in numsByMod.values(): if maxLength < len(group): ...
destroy-sequential-targets
Group nums by mod space
sr_vrd
0
7
destroy sequential targets
2,453
0.373
Medium
33,616
https://leetcode.com/problems/destroy-sequential-targets/discuss/2756511/Python-3-oror-Time%3A-1539-ms-Space%3A-34-MB
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: n=len(nums) t=[0 for i in range(n)] for i in range(len(nums)): t[i]=nums[i]%space z=Counter(t) t1=0 for i in z: t1=max(z[i],t1) ans=float('inf') for i...
destroy-sequential-targets
Python 3 || Time: 1539 ms , Space: 34 MB
koder_786
0
9
destroy sequential targets
2,453
0.373
Medium
33,617
https://leetcode.com/problems/destroy-sequential-targets/discuss/2756460/Python3-or-Modulus-%2B-Hashmap
class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: hmap=defaultdict(list) for i in nums: if i%space in hmap: occ,val=hmap[i%space] hmap[i%space]=[occ+1,min(val,i)] else: hmap[i%space]=[1,i] val...
destroy-sequential-targets
[Python3] | Modulus + Hashmap
swapnilsingh421
0
9
destroy sequential targets
2,453
0.373
Medium
33,618
https://leetcode.com/problems/next-greater-element-iv/discuss/2757259/Python3-intermediate-stack
class Solution: def secondGreaterElement(self, nums: List[int]) -> List[int]: ans = [-1] * len(nums) s, ss = [], [] for i, x in enumerate(nums): while ss and nums[ss[-1]] < x: ans[ss.pop()] = x buff = [] while s and nums[s[-1]] < x: buff.append(s.pop()) ...
next-greater-element-iv
[Python3] intermediate stack
ye15
1
38
next greater element iv
2,454
0.396
Hard
33,619
https://leetcode.com/problems/next-greater-element-iv/discuss/2757157/O(n-log-n)-Python-sorted-list-solution
class Solution: def secondGreaterElement(self, nums: List[int]) -> List[int]: from sortedcontainers import SortedList as slist l=len(nums) ans=[-1]*l print(ans) lst=slist([(nums[0], 0, [])], key=lambda x:(x[0], x[1])) i=1 while i<l: tmp=nums[i] ...
next-greater-element-iv
O(n log n) Python sorted list solution
mbeceanu
0
11
next greater element iv
2,454
0.396
Hard
33,620
https://leetcode.com/problems/next-greater-element-iv/discuss/2757122/Python-3Heap-%2B-Monotonic-queue-(hint-solution)
class Solution: def secondGreaterElement(self, nums: List[int]) -> List[int]: n = len(nums) first, second = [], [] ans = [-1] * n for i in range(n): # check if current greater than candidates waiting for second greater element wh...
next-greater-element-iv
[Python 3]Heap + Monotonic queue (hint solution)
chestnut890123
0
20
next greater element iv
2,454
0.396
Hard
33,621
https://leetcode.com/problems/next-greater-element-iv/discuss/2756483/Python3-or-Stack-%2B-Priority-Queue
class Solution: def secondGreaterElement(self, nums: List[int]) -> List[int]: st1,st2=[],[] heapify(st2) ans=[-1 for i in range(len(nums))] for i in range(len(nums)): while st2 and nums[-st2[0]]<nums[i]: ans[-heappop(st2)]=nums[i] while st1 and...
next-greater-element-iv
[Python3] | Stack + Priority Queue
swapnilsingh421
0
57
next greater element iv
2,454
0.396
Hard
33,622
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2770799/Easy-Python-Solution
class Solution: def averageValue(self, nums: List[int]) -> int: l=[] for i in nums: if i%6==0: l.append(i) return sum(l)//len(l) if len(l)>0 else 0
average-value-of-even-numbers-that-are-divisible-by-three
Easy Python Solution
Vistrit
2
107
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,623
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2764545/Python-Simple-Python-Solution
class Solution: def averageValue(self, nums: List[int]) -> int: s=0 k=0 for i in nums: if i%6==0: k+=1 s+=i if k==0: return 0 else: return(s//k)
average-value-of-even-numbers-that-are-divisible-by-three
[ Python ]🐍🐍Simple Python Solution ✅✅
sourav638
2
17
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,624
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2780425/Python-one-pass-O(n)
class Solution: def averageValue(self, nums: List[int]) -> int: _ans =[] for i in nums: if (i%2==0) and (i%3==0): _ans.append(i) return sum(_ans)//len(_ans) if len(_ans) > 0 else 0
average-value-of-even-numbers-that-are-divisible-by-three
Python one pass O(n)
ATHBuys
1
18
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,625
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2763059/Easiest-Python-Solution-oror-With-Explanation
class Solution: def averageValue(self, nums: List[int]) -> int: ans=0 # ans will store the sum of elements which are even and divisible by 3; cnt=0 # cnt will store the number of elements which are even and divisible by 3; for ele in nums: # Elements which a...
average-value-of-even-numbers-that-are-divisible-by-three
Easiest Python Solution || With Explanation ✔
akanksha984
1
75
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,626
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2828543/4-line-Python-solution
class Solution: def averageValue(self, nums: List[int]) -> int: valid_nums = [num for num in nums if num % 3 == 0 and num % 2 == 0] if len(valid_nums) == 0: return 0 return int(sum(valid_nums)/len(valid_nums))
average-value-of-even-numbers-that-are-divisible-by-three
4 line Python solution
lornedot
0
2
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,627
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2820623/python-O(n)-beats-66
class Solution: ## def averageValue(self, nums: List[int]) -> int: ## Time Complexity == O(n) lst = [i for i in nums if i%2 == 0 and i%3 ==0] return sum(lst) // len(lst) if lst else 0
average-value-of-even-numbers-that-are-divisible-by-three
python O(n) beats 66%
syedsajjad62
0
2
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,628
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2820592/Python-3-Simple-code
class Solution: def averageValue(self, nums: List[int]) -> int: res = 0 count = 0 for i in nums: # Even number that is divisible by 3 # Same conditions as divisible by 6 if i % 6 == 0: res += i count += 1 if count !...
average-value-of-even-numbers-that-are-divisible-by-three
[Python 3] Simple code
nguyentangnhathuy
0
1
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,629
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2795381/Easy-approach
class Solution: def averageValue(self, nums: List[int]) -> int: l=[] for i in nums: if i%6==0: l.append(i) if(len(l)>0): return sum(l)//len(l) else: return 0
average-value-of-even-numbers-that-are-divisible-by-three
Easy approach
nishithakonuganti
0
2
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,630
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2795283/Python-Easy-Solution-Time%3A-0(n)-Space%3A-0(1)
class Solution: def averageValue(self, nums: List[int]) -> int: s = 0 c = 0 for i, v in enumerate(nums): if v % 2 == 0 and v % 3 == 0: s += v c += 1 return math.floor(s / c) if c != 0 else 0
average-value-of-even-numbers-that-are-divisible-by-three
Python Easy Solution Time: 0(n) Space: 0(1)
ben-tiki
0
4
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,631
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2783199/2455.-Average-Value-of-Even-Numbers-That-Are-Divisible-by-Three
class Solution: def averageValue(self, nums: List[int]) -> int: add=0 lst=[] for i in range(len(nums)): if(nums[i]%3==0 and nums[i]%2==0): lst.append(nums[i]) x=len(lst) if(x==0): return 0 for i in range(x): add+=lst...
average-value-of-even-numbers-that-are-divisible-by-three
2455. Average Value of Even Numbers That Are Divisible by Three
knock_knock47
0
2
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,632
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2779971/Simple-Python-Solution
class Solution: def averageValue(self, nums: List[int]) -> int: list2 = [] for i in nums: if i%2 == 0: if i%3 == 0: list2.append(i) b = len(list2) sum1 = 0 if b>0: for i in list2: sum1 = sum1 + i ...
average-value-of-even-numbers-that-are-divisible-by-three
Simple Python Solution
dnvavinash
0
5
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,633
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2774622/Python-Simple-and-Crisp-Solution!
class Solution: def averageValue(self, nums: List[int]) -> int: total = 0 count = 0 for x in nums: if x % 2 == 0 and x % 3 == 0: total += x count += 1 if count == 0: return 0 return total // count
average-value-of-even-numbers-that-are-divisible-by-three
Python Simple and Crisp Solution!
vedanthvbaliga
0
2
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,634
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2770560/Python
class Solution: def averageValue(self, nums: List[int]) -> int: list1 = [x for x in nums if x%6 == 0] if (len(list1) > 0): return sum(list1)//len(list1) else: return 0
average-value-of-even-numbers-that-are-divisible-by-three
Python
user1079z
0
3
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,635
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2766941/easy-way-in-python
class Solution: def averageValue(self, nums: List[int]) -> int: s=0 count=0 for i in nums: if i%2==0 and i%3==0: print(i) s=s+i count=count+1 if count==0: return 0 else: return s//count
average-value-of-even-numbers-that-are-divisible-by-three
easy way in python
sindhu_300
0
13
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,636
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2764757/Python-Easy-Understanding-Solution
class Solution: def averageValue(self, nums: List[int]) -> int: n = 0 total = 0 for val in nums: if val % 6 == 0 and val != 0: n += 1 total += val return int(total/n) if n else 0
average-value-of-even-numbers-that-are-divisible-by-three
Python Easy Understanding Solution
MaverickEyedea
0
3
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,637
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2761942/One-pass
class Solution: def averageValue(self, nums: List[int]) -> int: sum_nums = count = 0 for n in nums: if not n % 6: sum_nums += n count += 1 return sum_nums // count if count > 0 else 0
average-value-of-even-numbers-that-are-divisible-by-three
One pass
EvgenySH
0
5
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,638
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2761930/Easy-FIlter-Solution
class Solution: def averageValue(self, nums: List[int]) -> int: filt =[i for i in nums if i % 6 == 0] return sum(filt) // len(filt) if len(filt) else 0
average-value-of-even-numbers-that-are-divisible-by-three
Easy FIlter Solution
cyber_kazakh
0
7
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,639
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2761255/Python3-oror-Easy-oror-O(N)
class Solution: def averageValue(self, nums: List[int]) -> int: sumo = 0 count = 0 for i in range(len(nums)): if nums[i] % 6 == 0: sumo += nums[i] count += 1 return 0 if (count == 0) else sumo//count
average-value-of-even-numbers-that-are-divisible-by-three
Python3 || Easy || O(N)
akshdeeprr
0
6
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,640
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2759518/python-O(n)
class Solution: def averageValue(self, nums: List[int]) -> int: temp_sum = 0 no = 0 for i in nums: if i % 3 == 0 and i % 2 == 0: temp_sum += i no += 1 if no == 0: return 0 else: ret...
average-value-of-even-numbers-that-are-divisible-by-three
python O(n)
akashp2001
0
5
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,641
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2759225/Python-Simple-Python-Solution
class Solution: def averageValue(self, nums: List[int]) -> int: result = 0 current_sum = 0 count = 0 for num in nums: if num % 2 == 0 and num % 3 == 0: current_sum = current_sum + num count = count + 1 if count == 0: return 0 else: result = current_sum // count return result
average-value-of-even-numbers-that-are-divisible-by-three
[ Python ] ✅✅ Simple Python Solution 🥳✌👍
ASHOK_KUMAR_MEGHVANSHI
0
11
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,642
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758828/Python%2BNumPy
class Solution: def averageValue(self, nums: List[int]) -> int: import numpy as np nums = [x for x in nums if x%6==0] return int(np.average(nums)) if nums else 0
average-value-of-even-numbers-that-are-divisible-by-three
Python+NumPy
Leox2022
0
3
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,643
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758699/Python-or-Three-lines
class Solution: def averageValue(self, nums: List[int]) -> int: xs = [m for m in nums if m % 6 == 0] n = len(xs) return 0 if n == 0 else sum(xs) // n
average-value-of-even-numbers-that-are-divisible-by-three
Python | Three lines
on_danse_encore_on_rit_encore
0
11
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,644
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758436/Python
class Solution: def averageValue(self, nums: List[int]) -> int: s = c = 0 for n in nums: if n % 6 == 0: s += n c += 1 return s // c if c else 0
average-value-of-even-numbers-that-are-divisible-by-three
Python
blue_sky5
0
7
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,645
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758382/Python-Solution(Brute-force-and-Optimal-approach)
class Solution: def averageValue(self, nums: List[int]) -> int: # Brute Force Approach, T.C = O(N), S.C = O(N) # N = len(nums) # ans = [] # for i in range(N): # if nums[i] % 2 == 0 and nums[i] % 3 == 0: # ans.append(nums[i]) # if len(ans) == 0: ...
average-value-of-even-numbers-that-are-divisible-by-three
Python Solution(Brute force and Optimal approach)
Ayush_Kumar27
0
6
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,646
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758362/Python3-Simple-2-lines
class Solution: def averageValue(self, nums: List[int]) -> int: q=[x for x in nums if not x%6] return q and sum(q)//len(q) or 0
average-value-of-even-numbers-that-are-divisible-by-three
Python3, Simple 2 lines
Silvia42
0
8
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,647
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758275/Python-Answer-Modulo
class Solution: def averageValue(self, nums: List[int]) -> int: res = [] for n in nums: if n % 3 == 0 and n % 2 == 0: res.append(n) return floor(sum(res) / len(res)) if len(res) > 0 else 0
average-value-of-even-numbers-that-are-divisible-by-three
[Python Answer🤫🐍🐍🐍] Modulo
xmky
0
4
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,648
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758257/Python-Solution
class Solution: def averageValue(self, nums: List[int]) -> int: # Brute Force Approach, T.C = O(N), S.C = O(N) # N = len(nums) # ans = [] # for i in range(N): # if nums[i] % 2 == 0 and nums[i] % 3 == 0: # ans.append(nums[i]) # if len(ans) == 0: ...
average-value-of-even-numbers-that-are-divisible-by-three
Python Solution
Ayush_Kumar27
0
4
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,649
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758181/Python-Easy-Solution-with-explanation
class Solution: def averageValue(self, nums: List[int]) -> int: ''' Algorithm: 1.declare total variable to hold the sum of all even numbers divisible by 3 2. declare a count variable to hold the number of the even numbers divisible by 3 3. loop over the array ...
average-value-of-even-numbers-that-are-divisible-by-three
Python Easy Solution with explanation
dee7
0
10
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,650
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758180/Python3-or-Implementation
class Solution: def averageValue(self, nums: List[int]) -> int: cnt=0 curr=0 for i in nums: if i%2==0 and i%3==0: curr+=i cnt+=1 if cnt==0: return 0 return curr//cnt
average-value-of-even-numbers-that-are-divisible-by-three
[Python3] | Implementation
swapnilsingh421
0
6
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,651
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758105/Python3-divisible-by-6
class Solution: def averageValue(self, nums: List[int]) -> int: cnt = total = 0 for x in nums: if x % 6 == 0: cnt += 1 total += x return cnt and total//cnt
average-value-of-even-numbers-that-are-divisible-by-three
[Python3] divisible by 6
ye15
0
11
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,652
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758056/easy-python-solutionororeasy-to-understand
class Solution: def averageValue(self, nums: List[int]) -> int: tot = 0 count=0 for ele in nums: if ele%2==0: if ele%3==0: tot+=ele count+=1 if count==0: return 0 else: return tot//cou...
average-value-of-even-numbers-that-are-divisible-by-three
✅✅easy python solution||easy to understand
chessman_1
0
2
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,653
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2758050/PythonStraight-forward-code
class Solution: def averageValue(self, nums: List[int]) -> int: sum = 0 divisor = 0 for num in nums: if num%2==0 and num%3==0: sum+=num divisor+=1 if divisor == 0: return 0 return int(sum/divisor)
average-value-of-even-numbers-that-are-divisible-by-three
【Python】Straight forward code ✅
gordonkwok
0
11
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,654
https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/discuss/2757986/python
class Solution: def averageValue(self, nums: List[int]) -> int: sum, count = 0,0 for n in nums: if n % 3 == 0 and n % 2 == 0: sum += n count += 1 if count == 0: return 0 return int(sum/count)
average-value-of-even-numbers-that-are-divisible-by-three
python
pradyumna04
0
5
average value of even numbers that are divisible by three
2,455
0.58
Easy
33,655
https://leetcode.com/problems/most-popular-video-creator/discuss/2758104/Python-Hashmap-solution-or-No-Sorting
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: memo = {} #tracking the max popular video count overall_max_popular_video_count = -1 #looping over the creators for i in range(len(creators)): if crea...
most-popular-video-creator
Python Hashmap solution | No Sorting
dee7
5
330
most popular video creator
2,456
0.441
Medium
33,656
https://leetcode.com/problems/most-popular-video-creator/discuss/2758289/Python-Answer-Heap-%2B-Dict-solution
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: pop = defaultdict(int) pop_small = defaultdict(list) for i,creator in enumerate(creators): pop[creator] += views[i] hea...
most-popular-video-creator
[Python Answer🤫🐍🐍🐍] Heap + Dict solution
xmky
1
43
most popular video creator
2,456
0.441
Medium
33,657
https://leetcode.com/problems/most-popular-video-creator/discuss/2842036/Python3-Linear-Hashmap-with-multiple-elements
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: # make a dict to save the viwer count and the highest view count counter = collections.defaultdict(lambda: [0, "", -1]) # go through the content creators for crea...
most-popular-video-creator
[Python3] - Linear Hashmap with multiple elements
Lucew
0
1
most popular video creator
2,456
0.441
Medium
33,658
https://leetcode.com/problems/most-popular-video-creator/discuss/2841104/python-dictionary-beats-96-of-answers
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: """ summary : each creator will get to be a key in a dictionary that contains the 1st item the sum of all the views so far the 2nd the id(in case if the value of m...
most-popular-video-creator
python dictionary beats 96% of answers
rojanrookhosh
0
1
most popular video creator
2,456
0.441
Medium
33,659
https://leetcode.com/problems/most-popular-video-creator/discuss/2824294/Simple-efficient-and-fast-Hashing-in-Python
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: d = {} max_views = 0 for creator, view, id in zip(creators, views, ids): # views, max viewed, id if creator not in d: d[creator] = ...
most-popular-video-creator
Simple efficient and fast - Hashing in Python
cgtinker
0
1
most popular video creator
2,456
0.441
Medium
33,660
https://leetcode.com/problems/most-popular-video-creator/discuss/2806466/Hasmap-Solution
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: d = defaultdict(int) maxmap,mx = {},0 for c,i,v in zip(creators,ids,views): d[c]+=v mx = max(mx,d[c]) if c not in maxmap or maxmap[c][...
most-popular-video-creator
Hasmap Solution
Rtriders
0
2
most popular video creator
2,456
0.441
Medium
33,661
https://leetcode.com/problems/most-popular-video-creator/discuss/2779895/Python-O(n)-solution-using-dictionary
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: creators_set = set() sum_map = defaultdict(int) order_map = {} n = len(views) for i in range(n): creators_set.add(creators[i]) ...
most-popular-video-creator
Python O(n) solution using dictionary
dhanu084
0
8
most popular video creator
2,456
0.441
Medium
33,662
https://leetcode.com/problems/most-popular-video-creator/discuss/2767144/Dictionary-for-creators-100-speed
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: d = dict() for c, i, v in zip(creators, ids, views): if c in d: d[c][0] += v if i in d[c][1]: d[c][1][i] += v ...
most-popular-video-creator
Dictionary for creators, 100% speed
EvgenySH
0
8
most popular video creator
2,456
0.441
Medium
33,663
https://leetcode.com/problems/most-popular-video-creator/discuss/2760646/straight-solution-with-python3-%2B-two-dict
class Solution: def mostPopularCreator(self, creators, ids, views):# List[int]) -> List[List[str]]: d = collections.defaultdict(dict) c = collections.defaultdict(int) res = list() for i in range(len(creators)): d[creators[i]][ids[i]] = views[i] ...
most-popular-video-creator
straight solution with python3 + two dict
kingfighters
0
16
most popular video creator
2,456
0.441
Medium
33,664
https://leetcode.com/problems/most-popular-video-creator/discuss/2759539/easy-python-solutionororeasy-to-understand
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: d1 = {} d2 = {} s = '' ans = [] for i in range(len(creators)): if creators[i] not in d1: d1[creators[i]] = [ids[i],views[i]] ...
most-popular-video-creator
✅✅easy python solution||easy to understand
chessman_1
0
22
most popular video creator
2,456
0.441
Medium
33,665
https://leetcode.com/problems/most-popular-video-creator/discuss/2758959/Python-O(n)-by-dictionary-w-Comment
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: # Constant to help reader understand code _ID, _View = 0, 1 # key: creator # value: total view count creatorView = defaultdict(in...
most-popular-video-creator
Python O(n) by dictionary [w/ Comment]
brianchiang_tw
0
21
most popular video creator
2,456
0.441
Medium
33,666
https://leetcode.com/problems/most-popular-video-creator/discuss/2758844/Python-3-Dictionaries-or-Easy-Implementation-or-Small
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: vi, v = defaultdict(int), defaultdict(list) for i in range(len(ids)): vi[creators[i]] += views[i] v[creators[i]].append([ids[i], views[i]]) max_v = ...
most-popular-video-creator
[Python 3] Dictionaries | Easy Implementation | Small
Rajesh1809
0
14
most popular video creator
2,456
0.441
Medium
33,667
https://leetcode.com/problems/most-popular-video-creator/discuss/2758350/Python-O(n)-SpaceTime-Solution
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: max_total_views = 0 total_views = collections.defaultdict(int) # track each creator's total view count for all videos most_viewed = {} # track each creator's most viewed vi...
most-popular-video-creator
Python O(n) Space/Time Solution
whatdoyumin
0
23
most popular video creator
2,456
0.441
Medium
33,668
https://leetcode.com/problems/most-popular-video-creator/discuss/2758338/Python3-Dictionary-and-Dictionary-of-Dictionary
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: autors={} popularity={} for a,i,v in zip(creators,ids,views): if a not in autors: autors[a]={} popularity[a]=0 autor...
most-popular-video-creator
Python3, Dictionary and Dictionary of Dictionary
Silvia42
0
11
most popular video creator
2,456
0.441
Medium
33,669
https://leetcode.com/problems/most-popular-video-creator/discuss/2758303/Simple-Python-O(n)
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: table = defaultdict(lambda: defaultdict(int)) for h, v, c in zip(creators, ids, views): table[h]['_'] += c table[h][v] = c max_count = max(...
most-popular-video-creator
Simple Python O(n)
ShuaSomeTea
0
17
most popular video creator
2,456
0.441
Medium
33,670
https://leetcode.com/problems/most-popular-video-creator/discuss/2758198/Python-Clean-Python-Solution-or-Dictionary-Counter
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: creator_total_views = Counter() d = collections.defaultdict(list) max_views = 0 for i in range(len(creators)): creator_total_views[creators[i]]+=views[i...
most-popular-video-creator
[Python] Clean Python Solution | Dictionary, Counter
daftpnk
0
26
most popular video creator
2,456
0.441
Medium
33,671
https://leetcode.com/problems/most-popular-video-creator/discuss/2758196/Python3-or-Hashmap-%2B-Sorting
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: hmap=defaultdict(list) hmap_view=defaultdict(int) n=len(ids) for i in range(n): hmap[creators[i]].append([ids[i],views[i]]) hmap_view[creato...
most-popular-video-creator
[Python3] | Hashmap + Sorting
swapnilsingh421
0
16
most popular video creator
2,456
0.441
Medium
33,672
https://leetcode.com/problems/most-popular-video-creator/discuss/2758113/Python3-hash-table
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: mp = defaultdict(list) total = defaultdict(int) for c, i, v in zip(creators, ids, views): mp[c].append((-v, i)) total[c] += v ans = [] ...
most-popular-video-creator
[Python3] hash table
ye15
0
19
most popular video creator
2,456
0.441
Medium
33,673
https://leetcode.com/problems/most-popular-video-creator/discuss/2758083/Python3-or-Dictionary
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: has={} for i in range(len(creators)): if creators[i] in has: has[creators[i]][0]+=views[i] if has[creators[i]][2]<views[i]: ...
most-popular-video-creator
Python3 | Dictionary
RickSanchez101
0
33
most popular video creator
2,456
0.441
Medium
33,674
https://leetcode.com/problems/most-popular-video-creator/discuss/2758065/Python-solution-with-dict
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: m = {} for i in range(len(creators)): creator = creators[i] view = views[i] id = ids[i] if creator not in m: ...
most-popular-video-creator
Python solution with dict
pradyumna04
0
23
most popular video creator
2,456
0.441
Medium
33,675
https://leetcode.com/problems/most-popular-video-creator/discuss/2758047/Python-or-O(n)
class Solution: def mostPopularCreator(self, creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]: total_views = {} first_max_view = {} for i in range(len(creators)): total_views[creators[i]] = total_views.get(creators[i], 0)+views[i] ...
most-popular-video-creator
Python | O(n)
diwakar_4
-1
35
most popular video creator
2,456
0.441
Medium
33,676
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758079/Check-next-10-next-100-next-1000-and-so-on...
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: i=n l=1 while i<=10**12: s=0 for j in str(i): s+=int(j) if s<=target: return i-n i//=10**l i+=1 i*=10**l ...
minimum-addition-to-make-integer-beautiful
Check next 10, next 100, next 1000 and so on...
shreyasjain0912
2
97
minimum addition to make integer beautiful
2,457
0.368
Medium
33,677
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2844877/Python3-Next-multiple-of-Ten-Digit-Accumulation
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: # the sum of digits by addition only gets smaller if we # get zeros certain digits by going to the next power # of ten for that digit, which increases the previous # digit by one # lets get ...
minimum-addition-to-make-integer-beautiful
[Python3] - Next multiple of Ten - Digit Accumulation
Lucew
0
1
minimum addition to make integer beautiful
2,457
0.368
Medium
33,678
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2776113/Easy-python-solution-with-good-comments
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: #function to get sum of the number def getsum(n): return sum([int(i) for i in str(n)]) #for the current digit place, if ones the 0, if tens then 1 as 10**1 =10 level=0 #storing an...
minimum-addition-to-make-integer-beautiful
Easy python solution with good comments
user9781TM
0
9
minimum addition to make integer beautiful
2,457
0.368
Medium
33,679
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2766456/One-pass-over-digits-97-speed
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: lst_n = list(map(int, str(n))) lst_n.reverse() ans = [] i = 0 while sum(lst_n) > target: if lst_n[i] > 0: diff = 10 - lst_n[i] ans.append(diff) ...
minimum-addition-to-make-integer-beautiful
One pass over digits, 97% speed
EvgenySH
0
19
minimum addition to make integer beautiful
2,457
0.368
Medium
33,680
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2766161/Python-Easy-Intuitive-Explanation
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: def helper(x): total = 0 while x > 0: total += x % 10 x //= 10 return total res = 0 base = 1 ...
minimum-addition-to-make-integer-beautiful
Python Easy Intuitive Explanation
MaverickEyedea
0
7
minimum addition to make integer beautiful
2,457
0.368
Medium
33,681
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2760295/Python3-Greedy-Algorithm
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: if sum([int(x) for x in str(n)]) <= target: return 0 else: arr = [int(x) for x in str(n)] arr.insert(0, 0) current = sum(arr) while True: ...
minimum-addition-to-make-integer-beautiful
Python3 Greedy Algorithm
xxHRxx
0
9
minimum addition to make integer beautiful
2,457
0.368
Medium
33,682
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758724/python3-Recursion-solution-for-reference
class Solution: def countDigits(self, n): c = 0 zdigit = 0 s = 0 while n: digit = n%10 s += digit n = n//10 c += 1 if digit and not zdigit: z = 10**(c-1) zdigit = (10*z-z...
minimum-addition-to-make-integer-beautiful
[python3] Recursion solution for reference
vadhri_venkat
0
12
minimum addition to make integer beautiful
2,457
0.368
Medium
33,683
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758679/Prefix-sum-solution-O(n)-in-python-3
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: if n<=target: return 0 nsp = [int(k) for k in str(n)] prefix_sum = [0]*len(nsp) for i in range(len(nsp)): if i == 0: prefix_sum[i] = nsp[i] else: ...
minimum-addition-to-make-integer-beautiful
Prefix sum solution O(n) in python 3
Arana
0
4
minimum addition to make integer beautiful
2,457
0.368
Medium
33,684
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758567/Simple-math
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: def sumofc(num): s = 0 while num != 0: s += num % 10 num = int(num/10) return s ans = 0 tmp = n mult = 1 #keep making last digit zero til...
minimum-addition-to-make-integer-beautiful
Simple math
praneeth_357
0
12
minimum addition to make integer beautiful
2,457
0.368
Medium
33,685
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758297/Python-Answer-Cheesed-solution
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: def getnum(num): s = str(num) total = 0 for c in s: total += int(c) return total t= getnum(n) st = str(n) res = 0 index = le...
minimum-addition-to-make-integer-beautiful
[Python Answer🤫🐍🐍🐍] Cheesed solution
xmky
0
7
minimum addition to make integer beautiful
2,457
0.368
Medium
33,686
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758269/Python3-Simple-and-Quick
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: i,d=n,10 while 1: if sum(int(ch) for ch in str(i)) <= target: return i-n i=(i//d)*d+d d*=10
minimum-addition-to-make-integer-beautiful
Python3, Simple and Quick
Silvia42
0
4
minimum addition to make integer beautiful
2,457
0.368
Medium
33,687
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758246/Python-solution-using-strings
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: if sum([int(x) for x in str(n)]) <= target: return 0 x = s = 0 a = str(n) for i in range(len(a)): s += int(a[i]) if s >= target: break x += 1 ...
minimum-addition-to-make-integer-beautiful
Python solution using strings
ayamdobhal
0
11
minimum addition to make integer beautiful
2,457
0.368
Medium
33,688
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758238/Python-100-faster
class Solution(object): def makeIntegerBeautiful(self, n, target): def round_up(n, decimals = 0): multiplier = 10 ** decimals return math.ceil(n * multiplier) / multiplier ln=len(str(n)) # print round_up(19,-2) def sumi(m): l=[] ...
minimum-addition-to-make-integer-beautiful
Python 100% faster
singhdiljot2001
0
19
minimum addition to make integer beautiful
2,457
0.368
Medium
33,689
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758208/Python3-or-Greedy-%2B-Maths
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: n=list(map(int,str(n))) curr=sum(n) ans=0 i=0 n.reverse() while curr>target: d=10-n[i] ans+=d*(10**i) curr=curr-n[i]+1 if i<len(n)-1: ...
minimum-addition-to-make-integer-beautiful
[Python3] | Greedy + Maths
swapnilsingh421
0
11
minimum addition to make integer beautiful
2,457
0.368
Medium
33,690
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758134/Python-or-O(logn)
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: def isLess(n): digit_sum = 0 while n!=0: digit_sum += n%10 n //= 10 return True if (digit_sum <= target) else False ans = 0 digit_position ...
minimum-addition-to-make-integer-beautiful
Python | O(logn)
diwakar_4
0
17
minimum addition to make integer beautiful
2,457
0.368
Medium
33,691
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758125/Python3-check-digits
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: diff = i = 0 while sum(map(int, str(n+diff))) > target: i += 1 diff = 10**i - n % 10**i return diff
minimum-addition-to-make-integer-beautiful
[Python3] check digits
ye15
0
14
minimum addition to make integer beautiful
2,457
0.368
Medium
33,692
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758121/Intuitive-solution-within-10-lines
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: num = [int(i) for i in str(n)] length, cur, out = len(num), 0, 0 for i in range(length): cur+=num[i] if cur>target or (cur==target and i<length-1 and sum(num[i+1:])>0): goal = ...
minimum-addition-to-make-integer-beautiful
Intuitive solution within 10 lines
30qwwq
0
10
minimum addition to make integer beautiful
2,457
0.368
Medium
33,693
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758082/Python-3-Handling-from-right-oror-Time%3A-44-ms-Space%3A-13.9-MB
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: def calc(s): ans=0 for i in s: ans+=int(i) return ans ans="" t=str(n) s=calc(t) while(s>target): i=len(t)-1 while(t[i]=="0")...
minimum-addition-to-make-integer-beautiful
Python 3 Handling from right || Time: 44 ms , Space: 13.9 MB
koder_786
0
15
minimum addition to make integer beautiful
2,457
0.368
Medium
33,694
https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/2758028/Python-simple-code-explained
class Solution: def makeIntegerBeautiful(self, n: int, target: int) -> int: #function to get sum of digits def sumofc(num): s = 0 while num != 0: s += num % 10 num = int(num/10) return s sumc = sumofc(n) ...
minimum-addition-to-make-integer-beautiful
Python simple code explained
pradyumna04
0
17
minimum addition to make integer beautiful
2,457
0.368
Medium
33,695
https://leetcode.com/problems/height-of-binary-tree-after-subtree-removal-queries/discuss/2760795/Python3-Triple-dict-depth-height-nodes_at_depth
class Solution: def treeQueries(self, root: Optional[TreeNode], queries: List[int]) -> List[int]: depth = {} height = {} nodes_at_depth = {} max_height = 0 def rec(n, d): nonlocal max_height if n is None: return 0 height_b...
height-of-binary-tree-after-subtree-removal-queries
Python3 Triple dict depth, height, nodes_at_depth
godshiva
0
12
height of binary tree after subtree removal queries
2,458
0.354
Hard
33,696
https://leetcode.com/problems/height-of-binary-tree-after-subtree-removal-queries/discuss/2758144/Python3-heights-by-level
class Solution: def treeQueries(self, root: Optional[TreeNode], queries: List[int]) -> List[int]: depth = {} height = {0 : 0} def fn(node, d): if not node: return 0 depth[node.val] = d height[node.val] = 1 + max(fn(node.left, d+1), fn(node.right...
height-of-binary-tree-after-subtree-removal-queries
[Python3] heights by level
ye15
0
56
height of binary tree after subtree removal queries
2,458
0.354
Hard
33,697
https://leetcode.com/problems/apply-operations-to-an-array/discuss/2786435/Python-Simple-Python-Solution-89-ms
class Solution: def applyOperations(self, nums: List[int]) -> List[int]: for i in range(len(nums)-1): if nums[i]==nums[i+1]: nums[i]*=2 nums[i+1]=0 temp = [] zeros = [] a=nums for i in range(len(a)): if a...
apply-operations-to-an-array
[ Python ] 🐍🐍 Simple Python Solution ✅✅ 89 ms
sourav638
3
31
apply operations to an array
2,460
0.671
Easy
33,698
https://leetcode.com/problems/apply-operations-to-an-array/discuss/2817847/Easy-Python-Solution
class Solution: def applyOperations(self, nums: List[int]) -> List[int]: l=[] c=0 for i in range(len(nums)-1): if(nums[i]==nums[i+1]): nums[i]=nums[i]*2 nums[i+1]=0 for i in nums: if i!=0: l.append(i) ...
apply-operations-to-an-array
Easy Python Solution
Vistrit
2
30
apply operations to an array
2,460
0.671
Easy
33,699