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/least-number-of-unique-integers-after-k-removals/discuss/2794255/python-super-easy-hashmap
class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: count = collections.Counter(arr) count = dict(sorted(count.items(), key = lambda x:x[1])) ans = len(count) for key in count: if count[key] <= k: ans -=1 k -= count[key] return ans
least-number-of-unique-integers-after-k-removals
python super easy hashmap
harrychen1995
0
4
least number of unique integers after k removals
1,481
0.569
Medium
22,100
https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/discuss/2685843/easy-python-solution
class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: numCount = {} # uniqueElem = set(arr) for num in arr : if num not in numCount.keys() : numCount[num] = 1 else : numCount[num] += 1 values = list(numCount.values()) values.sort() counter = 0 for v in values : if v <= k : k -= v counter += 1 else : break return len(values) - counter
least-number-of-unique-integers-after-k-removals
easy python solution
sghorai
0
32
least number of unique integers after k removals
1,481
0.569
Medium
22,101
https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/discuss/2488203/python-3-or-simple-hash-map-%2B-sorting-solution
class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: counts = sorted(collections.Counter(arr).values()) unique = len(counts) for count in counts: k -= count if k >= 0: unique -= 1 else: break return unique
least-number-of-unique-integers-after-k-removals
python 3 | simple hash map + sorting solution
dereky4
0
249
least number of unique integers after k removals
1,481
0.569
Medium
22,102
https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/discuss/2362319/Python-Counter.most_common
class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: most_common = Counter(arr).most_common() for i in range(len(most_common) - 1, -1, -1): if k >= most_common[i][1]: k -= most_common[i][1] else: return i + 1 return 0
least-number-of-unique-integers-after-k-removals
Python, Counter.most_common
blue_sky5
0
147
least number of unique integers after k removals
1,481
0.569
Medium
22,103
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/707611/Python-Binary-Search-or-Mathematical-function-definition-(75-Speed)
class Solution: def checker(self,arr, d, m, k) -> bool: ''' d -> days m -> bouquets k -> adjacent flowers return bool ''' arr = [10**9] + arr + [10**9] #appending array with maximum values idx = [] for i in range(len(arr)): if arr[i] > d: idx.append(i) cnt = 0 for i in range(len(idx)-1): # how many bouquet can we make out of an interval of valid flowers cnt += (idx[i+1] - idx[i] - 1) // k # return if count >= m return cnt >= m def minDays(self, arr: List[int], m: int, k: int) -> int: if m*k > len(arr): return -1 lo, hi = 1, max(arr) while(hi >= lo): mid = (hi+lo)//2 if(self.checker(arr, mid, m, k) == True): hi = mid else: lo = mid+1 if(hi == lo): break if self.checker(arr, lo, m, k): return lo else: return hi
minimum-number-of-days-to-make-m-bouquets
[Python] Binary Search | Mathematical function definition (75% Speed)
uds5501
3
223
minimum number of days to make m bouquets
1,482
0.557
Medium
22,104
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/686388/Python3-binary-search
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: if len(bloomDay) < m*k: return -1 # edge case def fn(d): """Return True if it is possible to make m bouquets on given day.""" mm, kk = m, k for x in bloomDay: kk = kk-1 if x <= d else k if not kk: mm, kk = mm-1, k if not mm: return True return False # "first true" binary search lo, hi = 0, max(bloomDay) while lo < hi: mid = lo + hi >> 1 if fn(mid): hi = mid else: lo = mid + 1 return lo
minimum-number-of-days-to-make-m-bouquets
[Python3] binary search
ye15
3
198
minimum number of days to make m bouquets
1,482
0.557
Medium
22,105
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/1995826/Python-or-Binary-Search
class Solution: def canWork(self, blooms, days, m, k): flowers = 0 for flower in blooms: flowers = flowers + 1 if (flower <= days) else 0 if flowers == k: m -= 1 flowers = 0 return m <= 0 def minDays(self, bloomDay: List[int], m: int, k: int) -> int: if len(bloomDay) < m * k: return -1 left, right = 1, max(bloomDay) while left < right: mid = (left + right) // 2 if self.canWork(bloomDay, mid, m, k): right = mid else: left = mid + 1 return left
minimum-number-of-days-to-make-m-bouquets
Python | Binary Search
leeteatsleep
2
160
minimum number of days to make m bouquets
1,482
0.557
Medium
22,106
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/1929329/Binary-Search-Python-Solution-oror-75-Faster-oror-Memory-less-than-50
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: def is_Possible(day): flowers=bouquet=0 for d in bloomDay: if d>day: flowers=0 else: flowers+=1 if flowers==k: bouquet+=1 ; flowers=0 return bouquet>=m if len(bloomDay)<m*k: return -1 lo=min(bloomDay) ; hi=max(bloomDay) while lo<hi: mid=(lo+hi)//2 if is_Possible(mid): hi=mid else: lo=mid+1 return hi
minimum-number-of-days-to-make-m-bouquets
Binary Search Python Solution || 75% Faster || Memory less than 50%
Taha-C
1
63
minimum number of days to make m bouquets
1,482
0.557
Medium
22,107
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/1859061/Python-Very-Easy-Brute-and-Optimal-Solutions
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: def isPossible(pluckDay): # this function to check if a day is possible will be used in all the below solutions. flowers = bouquet = 0 for d in bloomDay: if d > pluckDay: flowers = 0 else: flowers += 1 if flowers == k: bouquet += 1 flowers = 0 return bouquet >= m arr = sorted(list(set(bloomDay))) for day in arr: if isPossible(day): return day return -1
minimum-number-of-days-to-make-m-bouquets
✅ Python Very Easy Brute and Optimal Solutions
dhananjay79
1
96
minimum number of days to make m bouquets
1,482
0.557
Medium
22,108
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/1859061/Python-Very-Easy-Brute-and-Optimal-Solutions
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: def isPossible(pluckDay): # pluckDay: the day when we pluck the flower flowers = bouquet = 0 # flowers: to count number of flowers bloomed: bouquet: No of bouquets made for d in bloomDay: # traverse each bloomDay if d > pluckDay: flowers = 0 # if bloomDay > pluckDay, it means it means that flowers is not yet bloomed, so we cant pluck it on that day, reset it to zero as it break the adjacency streak else: # else the flower is bloomed flowers += 1 # increment the flower counter if flowers == k: # if we have k adjacents, then make a bouquet bouquet += 1 flowers = 0 # also the streak is broken as the flower is already used return bouquet >= m # return whether we had surpass or match the bouqeut making thresold if len(bloomDay) < m * k: return -1 # if number of flower is less than required, we cannot make it, so return -1 in that case l, h = min(bloomDay), max(bloomDay) while l < h: day = (l + h) // 2 if isPossible(day): h = day # if possible then we will check for lower days because we need to minimise. h = day bcoz we dont want lose what we got, else: l = day + 1 return h
minimum-number-of-days-to-make-m-bouquets
✅ Python Very Easy Brute and Optimal Solutions
dhananjay79
1
96
minimum number of days to make m bouquets
1,482
0.557
Medium
22,109
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/1859061/Python-Very-Easy-Brute-and-Optimal-Solutions
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: def isPossible(pluckDay): flowers = bouquet = 0 for d in bloomDay: if d > pluckDay: flowers = 0 else: flowers += 1 if flowers == k: bouquet += 1 flowers = 0 return bouquet >= m if len(bloomDay) < m * k: return -1 arr = sorted(list(set(bloomDay))) l = 0; h = len(arr) - 1 while l < h: mid = (l + h) // 2 day = arr[mid] if isPossible(day): h = mid else: l = mid + 1 return arr[h]
minimum-number-of-days-to-make-m-bouquets
✅ Python Very Easy Brute and Optimal Solutions
dhananjay79
1
96
minimum number of days to make m bouquets
1,482
0.557
Medium
22,110
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/2757638/Python-Solution
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: n = len(bloomDay) if n < m*k: return -1 S = sorted(bloomDay) l, r = 0, n-1 while l<r: mid = l + (r-l)//2 x = S[mid] i = 0 ans = 0 while i<n: if bloomDay[i]<=x: j = i temp = 0 while j < n and temp < k and bloomDay[j] <= x: temp += 1 j += 1 if temp == k: ans += 1 i = j else: i += 1 if ans >= m: r = mid else: l = mid + 1 return S[l]
minimum-number-of-days-to-make-m-bouquets
Python Solution
Tensor08
0
4
minimum number of days to make m bouquets
1,482
0.557
Medium
22,111
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/2585084/Python3-or-Solved-using-Binary-Search-with-Sliding-Window-Helper-Function!
class Solution: #let n = len(bloomDay)! #Time-Complexity: O(log(max(bloomDay)) * n) #Space-Complexity: O(1) def minDays(self, bloomDay: List[int], m: int, k: int) -> int: #First of all, we need to define a helper function that will return #number of bonquets that can be created based on number of days waited, #along with nonlocal references to bloomDay array input as well as #number of adjacent flowers to use/bonquet(k)! def helper(num_days): #i can use sliding window technique to reduce runtime from #initially quadratic to linear! nonlocal bloomDay, k #number of bonquets created so far! bonquets = 0 L, R = 0, 0 counter = 0 while L <= len(bloomDay) - k: #first, check if right pointed flower has bloom Day #as large as num_days! if(bloomDay[R] <= num_days): counter += 1 #check if current sliding window is size k! #Stopping condition: if current sliding window reaches size k! if(R - L + 1 == k): #check if counter == k! -> We can use current sliding #window of flowers to create a new bonquet! if(counter == k): bonquets += 1 counter = 0 L = R + 1 R = L continue else: #otherwise, if current window can't make a bonquet, #restrict the sliding window! #and take care of left value if it is the cause #of why we can't create bonquet! if(bloomDay[L] > num_days): L += 1 else: counter -= 1 L += 1 #and once, we can expand again, shift right pointer one right! R += 1 return bonquets #initialize number of days to wait as -1! ans = -1 #now, we can perform binary search on the search space of possible #waiting days! Low = 1, High = max(bloomDay) l, h = 1, max(bloomDay) #as long as search space has at least one element to consider, keep #iterating binary searches! while l <= h: mid = (l + h) // 2 num_bonquets = helper(mid) #check if num_bonquets we can make is at least m! if(num_bonquets >= m): ans = mid #search to left for better possible answer! h = mid - 1 continue else: l = mid + 1 continue return ans
minimum-number-of-days-to-make-m-bouquets
Python3 | Solved using Binary Search with Sliding Window Helper Function!
JOON1234
0
16
minimum number of days to make m bouquets
1,482
0.557
Medium
22,112
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/2065209/Easy-to-understand-Python-solution
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: if m*k > len(bloomDay): return -1 left = 1 right = max ( bloomDay ) #O(n) time complexity while (right> left):#O(logN) time complexity flowers = 0 bouquets = 0 mid = (right +left)//2 for i in bloomDay: #O(n) time complexity if i > mid: flowers = 0 if i <= mid: flowers = flowers +1 if flowers >= k: bouquets = bouquets+1 flowers =0 if bouquets >= m: right = mid elif bouquets < m: left = mid+1 return left # time O(NlogN) # space O(1)
minimum-number-of-days-to-make-m-bouquets
Easy to understand Python solution
mananiac
0
68
minimum number of days to make m bouquets
1,482
0.557
Medium
22,113
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/1889503/Python3-oror-Binary-Search
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: if m*k > len(bloomDay): return -1 low, high = min(bloomDay), max(bloomDay) ans = high while low <= high: mid = (low + high) // 2 if self.ifMinDays(bloomDay,mid,m,k): ans = mid high = mid - 1 else: low = mid + 1 return ans def ifMinDays(self,arr,day,m,k): arr = [(elem - day) for elem in arr] #find is it possible to find k consecutive elements, which are less than 1 (for m times) flowers = 0 for val in arr: if val > 0: flowers = 0 else: flowers += 1 if flowers == k: m -= 1 flowers = 0 if m > 0: return False return True
minimum-number-of-days-to-make-m-bouquets
Python3 || Binary Search
s_m_d_29
0
43
minimum number of days to make m bouquets
1,482
0.557
Medium
22,114
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/1815427/Python3-Binary-Search
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: left = min(bloomDay) right = max(bloomDay) answer = -1 while left <= right: mid = (left + right) // 2 if self.canMakeBouquets(mid, bloomDay, m, k): answer = mid right = mid - 1 else: left = mid + 1 return answer def canMakeBouquets(self, days, bloomDay, m, k): numFlowers = 0 numBouquets = 0 for bloom in bloomDay: if bloom <= days: numFlowers += 1 numBouquets += numFlowers // k if numFlowers == k: numFlowers = 0 else: numFlowers = 0 if numBouquets >= m: return True return False
minimum-number-of-days-to-make-m-bouquets
Python3 - Binary Search
adwaithks
0
40
minimum number of days to make m bouquets
1,482
0.557
Medium
22,115
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/1480473/Python-binary-search-solution
class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: if len(bloomDay) < m*k: return -1 l = 1 r = max(bloomDay) while l < r: mid = l + (r-l) // 2 if self.condition(mid,bloomDay,k,m): r = mid else: l = mid+1 return l def condition(self,n,nums,k,m): bouquets = 0 flowers = 0 for flower in nums: if flower <= n: bouquets += (flowers + 1) // k flowers = (flowers + 1) % k else: flowers = 0 return bouquets >= m
minimum-number-of-days-to-make-m-bouquets
Python binary search solution
Saura_v
0
77
minimum number of days to make m bouquets
1,482
0.557
Medium
22,116
https://leetcode.com/problems/xor-operation-in-an-array/discuss/942598/Simple-Python-Solutions
class Solution: def xorOperation(self, n: int, start: int) -> int: ans=0 for i in range(n): ans^=start+(2*i) return ans
xor-operation-in-an-array
Simple Python Solutions
lokeshsenthilkumar
8
604
xor operation in an array
1,486
0.842
Easy
22,117
https://leetcode.com/problems/xor-operation-in-an-array/discuss/942598/Simple-Python-Solutions
class Solution: def xorOperation(self, n: int, start: int) -> int: return reduce(operator.xor,[start+(2*i) for i in range(n)])
xor-operation-in-an-array
Simple Python Solutions
lokeshsenthilkumar
8
604
xor operation in an array
1,486
0.842
Easy
22,118
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1163962/Python3-Simple-44ms-Solution
class Solution: def xorOperation(self, n: int, start: int) -> int: ans = start for i in range(1 , n): ans ^= start + (2 * i) return ans
xor-operation-in-an-array
[Python3] Simple 44ms Solution
VoidCupboard
3
72
xor operation in an array
1,486
0.842
Easy
22,119
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2790634/Python-oror-Simple-Solution-oror-Beginner-Friendly
class Solution: def xorOperation(self, n: int, start: int) -> int: xor = 0 for i in range(n): xor = xor ^ start start+=2 return xor
xor-operation-in-an-array
Python || Simple Solution || Beginner Friendly
hasan2599
2
97
xor operation in an array
1,486
0.842
Easy
22,120
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2605941/SIMPLE-PYTHON3-SOLUTION-easiest-code
class Solution: def xorOperation(self, n: int, start: int) -> int: ans = 0 for i in range(n): ans ^= start start+=2 return ans
xor-operation-in-an-array
✅✔ SIMPLE PYTHON3 SOLUTION ✅✔ easiest code
rajukommula
2
108
xor operation in an array
1,486
0.842
Easy
22,121
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1147864/A-Simple-And-Readable-Solution-For-This-Problem-(4-lines)
class Solution: def xorOperation(self, n: int, start: int) -> int: ans = start for i in range(1 , n): ans ^= start + (2 * i) return(ans)
xor-operation-in-an-array
A Simple And Readable Solution For This Problem (4 lines)
PleaseDontHelp
2
54
xor operation in an array
1,486
0.842
Easy
22,122
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1950431/One-line-Solution-in-python
class Solution: def xorOperation(self, n: int, start: int) -> int: return reduce(lambda x,y:x^y,[start+2*i for i in range(n)])
xor-operation-in-an-array
One line Solution in python
amannarayansingh10
1
70
xor operation in an array
1,486
0.842
Easy
22,123
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1853781/python-4-diffrent-implimentation-or-brute-force-or-time-O(n)-or-space-O(n)
class Solution: def xorOperation(self, n: int, start: int) -> int: # 1st # return reduce(lambda x,y: x^y,[ start+2*i for i in range(n)]) # 2nd # return eval("^".join([str(start+2*i) for i in range(n)])) # 3rd # return reduce(operator.xor,[start+(2*i) for i in range(n)]) # 4th ans = 0 nums = [start + n * 2 for n in range(n)] for n in nums: ans = ans ^ n return ans
xor-operation-in-an-array
python 4 diffrent implimentation | brute force | time O(n) | space O(n)
YaBhiThikHai
1
35
xor operation in an array
1,486
0.842
Easy
22,124
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1306618/Easy-Python-Solution(99.17)
class Solution: def xorOperation(self, n: int, start: int) -> int: c=0 for i in range(n): c^=(start+2*i) return c
xor-operation-in-an-array
Easy Python Solution(99.17%)
Sneh17029
1
249
xor operation in an array
1,486
0.842
Easy
22,125
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2845175/Smple-Python-solution
class Solution: def xorOperation(self, n: int, start: int) -> int: nums = [] #nums.append(start) for i in range(n): nums.append(start + (2 * i)) res = start for i in range(1,len(nums)): res = res ^ nums[i] return res
xor-operation-in-an-array
Smple Python solution
Shagun_Mittal
0
1
xor operation in an array
1,486
0.842
Easy
22,126
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2830045/Python-Solution-Simple-maths-oror-EASY
class Solution: def xorOperation(self, n: int, start: int) -> int: xor=start + 2 * 0 for i in range(1,n): xor=xor^(start + 2 * i) return xor
xor-operation-in-an-array
Python Solution - Simple maths || EASY
T1n1_B0x1
0
2
xor operation in an array
1,486
0.842
Easy
22,127
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2824939/python-simple-solution-or-memory-efficientm
class Solution: def xorOperation(self, n: int, start: int) -> int: nums=[start+2*i for i in range(n)] k=nums[0] for i in range(1,len(nums)): k=k^nums[i] return k
xor-operation-in-an-array
python simple solution | memory efficientm
nandagaonkartik
0
3
xor operation in an array
1,486
0.842
Easy
22,128
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2698830/Simple-python-code-with-explanation
class Solution: def xorOperation(self, n, start): #create a variable i to use it as a iterater i = 0 #create a variable m to store the value of result m = 0 #this while loop runs untill i value less than n while i < n: #store (m ^ (start + (2*i))) value in m m = m ^ (start + (2*i)) #increase the value of i by 1 i = i + 1 #after breaking out of the while loop #return the m value return m
xor-operation-in-an-array
Simple python code with explanation
thomanani
0
4
xor operation in an array
1,486
0.842
Easy
22,129
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2673904/Python3-solution%3A-with-reduce-and-without-reduce
class Solution: def xorOperation(self, n: int, start: int) -> int: return reduce(lambda x, y: x ^ y, [start + x*2 for x in range(n)])
xor-operation-in-an-array
Python3 solution: with reduce and without reduce
sipi09
0
1
xor operation in an array
1,486
0.842
Easy
22,130
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2673904/Python3-solution%3A-with-reduce-and-without-reduce
class Solution: def xorOperation(self, n: int, start: int) -> int: list_ = [start + x*2 for x in range(n)] ans = list_[0] for x in range(1,len(list_)): ans = ans ^ list_[x] return ans
xor-operation-in-an-array
Python3 solution: with reduce and without reduce
sipi09
0
1
xor operation in an array
1,486
0.842
Easy
22,131
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2668687/Simple-Python-Solution-or-TC%3A-O(n)-or-SC%3A-O(1)
class Solution: def xorOperation(self, n: int, start: int) -> int: xor=0 for i in range(n): xor^=(start+2*i) return xor
xor-operation-in-an-array
Simple Python Solution | TC: O(n) | SC: O(1)
Siddharth_singh
0
2
xor operation in an array
1,486
0.842
Easy
22,132
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2664777/Python-or-Straightforward-XOR
class Solution: def xorOperation(self, n: int, start: int) -> int: ans=0 for i in range(n): ans^=(start+2*i) return ans
xor-operation-in-an-array
Python | Straightforward XOR
Prithiviraj1927
0
7
xor operation in an array
1,486
0.842
Easy
22,133
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2613516/XOR-operation-in-an-array
class Solution: def xorOperation(self, n: int, start: int) -> int: res=start for i in range(1,n): res=res^(start+2*i) return res # nums=[start+2*i for i in range(n)] # xor=nums[0] # for i in range(1,n): # xor=xor^nums[i] # return xor
xor-operation-in-an-array
XOR operation in an array
shivansh2001sri
0
24
xor operation in an array
1,486
0.842
Easy
22,134
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2313574/XOR-operation-in-an-Array
```class Solution: def xorOperation(self, n: int, start: int) -> int: lst = [] for i in range(n): lst.append(start + (i*2)) XOR = lst[0] for i in range(1,len(lst)): XOR ^= lst[i] return (XOR)
xor-operation-in-an-array
XOR operation in an Array
Jonny69
0
25
xor operation in an array
1,486
0.842
Easy
22,135
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2219868/Faster-than-99.57-of-Python3-online-submissions-(Runtime%3A-24-ms)
class Solution: def xorOperation(self, n: int, start: int) -> int: num = 0 st_num = start for i in range(1,n): num = start + 2 * i st_num ^= num return st_num
xor-operation-in-an-array
Faster than 99.57% of Python3 online submissions (Runtime: 24 ms)
salsabilelgharably
0
52
xor operation in an array
1,486
0.842
Easy
22,136
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2114283/Easy-Python-code
class Solution: def xorOperation(self, n: int, start: int) -> int: nums = [] for i in range(n): nums.append(start+(2*i)) a = 0 for i in nums: a = a^i return a
xor-operation-in-an-array
Easy Python code
prernaarora221
0
28
xor operation in an array
1,486
0.842
Easy
22,137
https://leetcode.com/problems/xor-operation-in-an-array/discuss/2029917/Python-Simple-solution
class Solution: def xorOperation(self, n: int, start: int) -> int: xor = 0 for i in range(n): xor ^= start+2*i return xor
xor-operation-in-an-array
Python Simple solution
Vamsidhar01
0
31
xor operation in an array
1,486
0.842
Easy
22,138
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1927519/Python-Clean-and-Simple!
class Solution: def xorOperation(self, n, start): return reduce(operator.xor, (start+2*i for i in range(n)))
xor-operation-in-an-array
Python - Clean and Simple!
domthedeveloper
0
68
xor operation in an array
1,486
0.842
Easy
22,139
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1927519/Python-Clean-and-Simple!
class Solution: def xorOperation(self, n, start): last = start + 2 * (n-1) if start % 4 <= 1: match n % 4: case 1: return last case 2: return 2 case 3: return 2 ^ last case _: return 0 else: match n % 4: case 1: return start case 2: return start ^ last case 3: return start ^ 2 case _: return start ^ 2 ^ last
xor-operation-in-an-array
Python - Clean and Simple!
domthedeveloper
0
68
xor operation in an array
1,486
0.842
Easy
22,140
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1867066/Python-easy-solution
class Solution: def xorOperation(self, n: int, start: int) -> int: nums = [start + 2 * i for i in range(n)] xor = nums[0] for i in range(1, len(nums)): xor ^= nums[i] return xor
xor-operation-in-an-array
Python easy solution
alishak1999
0
38
xor operation in an array
1,486
0.842
Easy
22,141
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1864512/Easy-to-understand-Python
class Solution: def xorOperation(self, n: int, start: int) -> int: i = 0 nums = [] val = 0 while i < n: num = start + 2 * i nums.append(num) i += 1 for j in nums: val ^= j return val
xor-operation-in-an-array
Easy to understand Python
natscripts
0
15
xor operation in an array
1,486
0.842
Easy
22,142
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1798376/1-Line-Python-Solution-oror-85-Faster(32ms)-oror-Memory-less-than-85
class Solution: def xorOperation(self, n: int, start: int) -> int: return reduce(lambda x, y: x ^ y, [start+i*2 for i in range(n)])
xor-operation-in-an-array
1-Line Python Solution || 85% Faster(32ms) || Memory less than 85%
Taha-C
0
35
xor operation in an array
1,486
0.842
Easy
22,143
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1171065/Simple-Python-Solutions%3A-Multiple-Approaches_O(n)
class Solution: def xorOperation(self, n: int, start: int) -> int: res = start for i in range(1,n): res^=start+2*i return res
xor-operation-in-an-array
Simple Python Solutions: Multiple Approaches_O(n)
smaranjitghose
0
38
xor operation in an array
1,486
0.842
Easy
22,144
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1145256/Python-O(n)-Time-and-O(1)-space
class Solution: def xorOperation(self, n: int, start: int) -> int: #nums = [start+2*i for i in range(n)] # we don't need this nums list as it is increasing the space comp. for i in range(n): if i==0: xor = start+2*i else: xor=xor^(start+2*i) return xor
xor-operation-in-an-array
Python O(n) Time and O(1) space
krishy557
0
86
xor operation in an array
1,486
0.842
Easy
22,145
https://leetcode.com/problems/xor-operation-in-an-array/discuss/1107385/Python-one-loop-solution-beats-61
class Solution: def xorOperation(self, n: int, start: int) -> int: nums = [] bitwise_result = 0 for i in range(n): temp = start+2*i bitwise_result ^= temp nums.append(start+2*i) return bitwise_result
xor-operation-in-an-array
Python one loop solution beats 61%
dee7
0
62
xor operation in an array
1,486
0.842
Easy
22,146
https://leetcode.com/problems/xor-operation-in-an-array/discuss/836658/Python-3-24-ms-Solution
class Solution: def xorOperation(self, n: int, start: int) -> int: result = start for i in range(1, n): result = result ^ (start + 2 * i) # re-compute XOR with new start return result
xor-operation-in-an-array
Python 3 24 ms Solution
Skyfall2017
0
146
xor operation in an array
1,486
0.842
Easy
22,147
https://leetcode.com/problems/xor-operation-in-an-array/discuss/697920/Python3-1-line
class Solution: def xorOperation(self, n: int, start: int) -> int: return reduce(xor, (start + 2*i for i in range(n)))
xor-operation-in-an-array
[Python3] 1-line
ye15
0
51
xor operation in an array
1,486
0.842
Easy
22,148
https://leetcode.com/problems/xor-operation-in-an-array/discuss/697859/Python-Easy-2-Solutions-Constant-Space-or-Reduce
class Solution: def xorOperation(self, n: int, start: int) -> int: nums = [start + 2*i for i in range(n)] ans = reduce(lambda x,y: x^y, nums) return ans
xor-operation-in-an-array
[Python] Easy - 2 Solutions - Constant Space | Reduce
ambassadorSp0ck
0
41
xor operation in an array
1,486
0.842
Easy
22,149
https://leetcode.com/problems/xor-operation-in-an-array/discuss/697859/Python-Easy-2-Solutions-Constant-Space-or-Reduce
class Solution: def xorOperation(self, n: int, start: int) -> int: ans = 0 for i in range(n): ans ^= start + 2*i return ans
xor-operation-in-an-array
[Python] Easy - 2 Solutions - Constant Space | Reduce
ambassadorSp0ck
0
41
xor operation in an array
1,486
0.842
Easy
22,150
https://leetcode.com/problems/xor-operation-in-an-array/discuss/697746/Simple-Python-While-Loop-O(1)-Space-O(N)-time
class Solution: def xorOperation(self, n: int, start: int) -> int: i = 0 res = 0 while i<n: val = start + 2*i res ^= val i+=1 return res
xor-operation-in-an-array
Simple Python While Loop, O(1) Space, O(N) time
steven6
0
67
xor operation in an array
1,486
0.842
Easy
22,151
https://leetcode.com/problems/xor-operation-in-an-array/discuss/697716/PythonPython3-XOR-Operation-in-an-Array
class Solution: def xorOperation(self, n: int, start: int) -> int: k = 0 for x in range(start, start+(2*n),2): k ^= x return k
xor-operation-in-an-array
[Python/Python3] XOR Operation in an Array
newborncoder
0
183
xor operation in an array
1,486
0.842
Easy
22,152
https://leetcode.com/problems/making-file-names-unique/discuss/1646944/Very-simple-python3-solution-using-hashmap-and-comments
class Solution: def getFolderNames(self, names: List[str]) -> List[str]: # names : array of names # n : size of names # create folders at the i'th minute for each name = names[i] # If name was used previously, append a suffix "(k)" - note parenthesis - where k is the smallest pos int # return an array of strings where ans[i] is the actual saved variant of names[i] n = len(names) dictNames = {} ans = ['']*n # enumerate to grab index so we can return ans list in order for idx, name in enumerate(names): # check if we have seen this name before if name in dictNames: # if we have grab the next k using last successful low (k) suffix k = dictNames[name] # track the name we started so we can update the dict namestart = name # cycle through values of increasing k until we are not in a previously used name while name in dictNames: name = namestart + f"({k})" k += 1 # update the name we started with to the new lowest value of k dictNames[namestart] = k # add the new name with k = 1 so if we see this name with the suffix dictNames[name] = 1 else: # we havent seen this name so lets start with 1 dictNames[name] = 1 # build the solution ans[idx] = name return ans
making-file-names-unique
Very simple python3 solution using hashmap and comments
jumpstarter
3
307
making file names unique
1,487
0.359
Medium
22,153
https://leetcode.com/problems/making-file-names-unique/discuss/699519/Python3-9-line-concise-solution
class Solution: def getFolderNames(self, names: List[str]) -> List[str]: seen = {} for name in names: if name not in seen: seen[name] = 1 else: k = seen[name] while (suffix := f"{name}({k})") in seen: k += 1 seen[name] = k+1 seen[suffix] = 1 return seen.keys()
making-file-names-unique
[Python3] 9-line concise solution
ye15
2
88
making file names unique
1,487
0.359
Medium
22,154
https://leetcode.com/problems/making-file-names-unique/discuss/1224189/Straightforward-8-line-Python
class Solution: def getFolderNames(self, names: List[str]) -> List[str]: res = {} for i in names: candidate = i while candidate in res: candidate = i+f'({res[i]})' res[i] += 1 res[candidate] = 1 return list(res.keys())
making-file-names-unique
Straightforward 8 line Python
xiaokonglong
1
107
making file names unique
1,487
0.359
Medium
22,155
https://leetcode.com/problems/making-file-names-unique/discuss/1447306/Simple-Python-O(n)(amortized)-dictionary%2Bset-solution
class Solution: def getFolderNames(self, names: List[str]) -> List[str]: ret, ret_set, name2nextSuffix = [], set(), {} for n in names: if n not in name2nextSuffix: ret.append(n) ret_set.add(n) name2nextSuffix[n] = 1 else: suffix = name2nextSuffix[n] while n+'('+str(suffix)+')' in ret_set: suffix += 1 name2nextSuffix[n] += 1 name2nextSuffix[n] += 1 name2nextSuffix[n+'('+str(suffix)+')'] = 1 ret.append(n+'('+str(suffix)+')') return ret
making-file-names-unique
Simple Python O(n)(amortized) dictionary+set solution
Charlesl0129
0
343
making file names unique
1,487
0.359
Medium
22,156
https://leetcode.com/problems/making-file-names-unique/discuss/1560546/Python-Linear-solution-using-a-dictionary
class Solution: def getFolderNames(self, names: List[str]) -> List[str]: d, res = {}, [] for name in names: if name in d: orig_name = name # get the smallest positive key key = d[name] while(name in d): name = orig_name + "({})".format(key) key += 1 d[name] = 1 # memoization done so as to get the latest version of this next time d[orig_name] = key else: d[name] = 1 res.append(name) return res
making-file-names-unique
[Python] Linear solution using a dictionary
vasu6
-1
221
making file names unique
1,487
0.359
Medium
22,157
https://leetcode.com/problems/avoid-flood-in-the-city/discuss/1842629/Python-easy-to-read-and-understand-or-heap
class Solution: def avoidFlood(self, rains: List[int]) -> List[int]: pq = [] fill = set() d = collections.defaultdict(list) ans = [] for i, rain in enumerate(rains): d[rain].append(i) for rain in rains: if rain > 0: if rain in fill: return [] fill.add(rain) d[rain].pop(0) if d[rain]: heapq.heappush(pq, d[rain][0]) ans.append(-1) else: if pq: ind = heapq.heappop(pq) ans.append(rains[ind]) fill.remove(rains[ind]) else: ans.append(1) return ans
avoid-flood-in-the-city
Python easy to read and understand | heap
sanial2001
0
193
avoid flood in the city
1,488
0.261
Medium
22,158
https://leetcode.com/problems/avoid-flood-in-the-city/discuss/700820/Python3-20-line
class Solution: def avoidFlood(self, rains: List[int]) -> List[int]: days = dict() #days of raining for a given lake for d, lake in enumerate(rains): if lake: days.setdefault(lake, deque()).append(d) ans, hp = [], [] #min-heap full = set() #full lakes for d, lake in enumerate(rains): if lake: if lake in full: return [] full.add(lake) days[lake].popleft() if days[lake]: heappush(hp, (days[lake][0], lake)) ans.append(-1) else: if hp: _, lake = heappop(hp) full.remove(lake) ans.append(lake) else: ans.append(1) return ans
avoid-flood-in-the-city
[Python3] 20-line
ye15
0
30
avoid flood in the city
1,488
0.261
Medium
22,159
https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/discuss/702027/Python3-Prim's-algo
class Solution: def findCriticalAndPseudoCriticalEdges(self, n: int, edges: List[List[int]]) -> List[List[int]]: graph = dict() for u, v, w in edges: graph.setdefault(u, []).append((v, w)) graph.setdefault(v, []).append((u, w)) ref = self.mst(n, graph) critical, pseudo = [], [] for i in range(len(edges)): if self.mst(n, graph, exclude=edges[i][:2]) > ref: critical.append(i) elif self.mst(n, graph, init=edges[i]) == ref: pseudo.append(i) return [critical, pseudo] def mst(self, n, graph, init=None, exclude=None): """Return weight of MST of given graph using Prim's algo""" def visit(u): """Mark node and put its edges to priority queue""" marked[u] = True for v, w in graph.get(u, []): if exclude and u in exclude and v in exclude: continue if not marked[v]: heappush(pq, (w, u, v)) ans = 0 marked = [False]*n pq = [] #min prioirty queue if init: u, v, w = init ans += w marked[u] = marked[v] = True visit(u) or visit(v) else: visit(0) while pq: w, u, v = heappop(pq) if marked[u] and marked[v]: continue ans += w if not marked[u]: visit(u) if not marked[v]: visit(v) return ans if all(marked) else inf
find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree
[Python3] Prim's algo
ye15
4
355
find critical and pseudo critical edges in minimum spanning tree
1,489
0.526
Hard
22,160
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2213970/Python3-one-pass-solution-beats-99.20-of-submissions
class Solution: def average(self, salary: List[int]) -> float: minimum = float("inf") maximum = float("-inf") i = 0 sums = 0 while i<len(salary): minimum = min(minimum, salary[i]) maximum = max(maximum, salary[i]) sums+=salary[i] i+=1 return (sums - (maximum+minimum))/(i-2)
average-salary-excluding-the-minimum-and-maximum-salary
📌 Python3 one pass solution beats 99.20% of submissions
Dark_wolf_jss
6
207
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,161
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/997370/Python3-O(nlogn)-time-O(1)-space
class Solution: def average(self, salary: List[int]) -> float: salary = sorted(salary)[1:len(salary)-1] return sum(salary) / len(salary)
average-salary-excluding-the-minimum-and-maximum-salary
Python3 O(nlogn) time O(1) space
peterhwang
5
809
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,162
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/1804267/python3-or-fastest-solution-90
class Solution: def average(self, salary: List[int]) -> float: salary.remove(min(salary)) salary.remove(max(salary)) return sum(salary)/len(salary)
average-salary-excluding-the-minimum-and-maximum-salary
✔📌python3 | fastest solution 90%
Anilchouhan181
3
284
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,163
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/708278/PythonPython3-Average-Salary-Excluding-the-minimum-and-Maximum-Salary
class Solution: def average(self, salary: List[int]) -> float: salary.sort() salary = salary[1:-1] return sum(salary)/(len(salary))
average-salary-excluding-the-minimum-and-maximum-salary
[Python/Python3] Average Salary Excluding the minimum and Maximum Salary
newborncoder
2
251
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,164
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2272876/Python3-One-line-O(n)-solution
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary) - min(salary) - max(salary)) / (len(salary) - 2)
average-salary-excluding-the-minimum-and-maximum-salary
[Python3] One line O(n) solution
geka32
1
84
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,165
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2099605/PYTHON-or-Easy-One-Liner-Solution
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary) - max(salary) - min(salary)) / (len(salary) - 2)
average-salary-excluding-the-minimum-and-maximum-salary
PYTHON | Easy One Liner Solution
shreeruparel
1
109
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,166
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/1816156/1-Line-Python-Solution-oror-90-Faster-(32ms)-oror-Memory-less-than-30
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary)-max(salary)-min(salary))/(len(salary)-2)
average-salary-excluding-the-minimum-and-maximum-salary
1-Line Python Solution || 90% Faster (32ms) || Memory less than 30%
Taha-C
1
112
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,167
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/1283712/Python-or-Simple-sorting-and-slicing-or-Faster-than-92
class Solution: def average(self, salary: List[int]) -> float: #using slicing and sorting simple res=0.0 n=len(salary) return sum(sorted(salary)[1:n-1])/(n-2)
average-salary-excluding-the-minimum-and-maximum-salary
Python | Simple sorting and slicing | Faster than 92%
ana_2kacer
1
35
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,168
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/1280922/99-faster-easy-to-understand
class Solution: def average(self, salary: List[int]) -> float: l = len(salary) salary = sorted(salary) return (sum(salary[1 : l-1])) / (l - 2)
average-salary-excluding-the-minimum-and-maximum-salary
99 % faster - easy to understand
user2227R
1
100
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,169
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/835899/Python-One-line
class Solution: def average(self, salary: List[int]) -> float: return sum(sorted(salary)[1:-1])/(len(salary)-2)
average-salary-excluding-the-minimum-and-maximum-salary
Python One line
airksh
1
45
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,170
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/835899/Python-One-line
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary)-max(salary)-min(salary)) / (len(salary)-2) # TC: O(N) # SC: O(1)
average-salary-excluding-the-minimum-and-maximum-salary
Python One line
airksh
1
45
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,171
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/768672/Python-One-liner-easy-understanding
class Solution: def average(self, salary: List[int]) -> float: return((sum(salary)-max(salary)-min(salary))/(len(salary)-2))
average-salary-excluding-the-minimum-and-maximum-salary
Python One liner easy understanding
shubhamthrills
1
94
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,172
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2845794/Python-Solution
class Solution: def average(self, salary: List[int]) -> float: salary.sort() return(sum(salary[1:-1])/(len(salary)-2))
average-salary-excluding-the-minimum-and-maximum-salary
Python Solution
CEOSRICHARAN
0
1
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,173
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2843049/python-easy-sol-time-O(n)-and-space-O(1)
class Solution: def average(self, salary: List[int]) -> float: low=10**7 high=-1 n=len(salary) summ=0 for i in range(len(salary)): low=min(low , salary[i]) high=max(high , salary[i]) summ+=salary[i] # print(summ , low , high) summ=summ-low-high return summ/(n-2)
average-salary-excluding-the-minimum-and-maximum-salary
python easy sol time O(n) and space O(1)
sintin1310
0
1
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,174
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2834599/Python3%3A-Dumb-yet-effective
class Solution: def average(self, salary: List[int]) -> float: salary.sort() salary.remove(salary[0]) salary.remove(salary[-1]) return sum(salary) / len(salary)
average-salary-excluding-the-minimum-and-maximum-salary
Python3: Dumb, yet effective
Peanut_in_Motion
0
1
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,175
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2807610/Simple-one-liner
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary) - min(salary) - max(salary)) / (len(salary) - 2)
average-salary-excluding-the-minimum-and-maximum-salary
Simple one-liner
xHype
0
2
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,176
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2802482/Python-One-Linear-Time-Complexity-O(1)
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary) - min(salary) - max(salary))/(len(salary)- 2)
average-salary-excluding-the-minimum-and-maximum-salary
Python One Linear - Time Complexity - O(1)
danishs
0
3
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,177
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2786075/FASTER-THAN-95.51-PYTHON-100-EASY-TO-UNDERSTANDSIMPLECLEAN
class Solution: def average(self, salary: List[int]) -> float: sort = sorted(salary) sort.pop(0) sort.pop(-1) sum = 0 for i in range(len(sort)): sum += sort[i] sum /= len(sort) return sum Please upvote if this helped you so others can see it too!!! Proof of efficiency --> https://assets.leetcode.com/users/images/385e4f5e-5068-412c-9618-3226c2e6ade7_1667759070.1927059.png
average-salary-excluding-the-minimum-and-maximum-salary
🔥FASTER THAN 95.51% PYTHON 100% EASY TO UNDERSTAND/SIMPLE/CLEAN🔥
YuviGill
0
3
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,178
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2780387/Average-Salary-or-Python-or-Simple-Maths
class Solution: def average(self, salary: List[int]) -> float: n = len(salary) - 2 sum_sal = sum(salary) mx_sal = max(salary) mn_sal = min(salary) average_sal = ((sum_sal - mx_sal) - mn_sal)/n return average_sal
average-salary-excluding-the-minimum-and-maximum-salary
Average Salary | Python | Simple Maths
jashii96
0
1
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,179
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2780261/python-runtime-31ms
class Solution: def average(self, salary: List[int]) -> float: a=sorted(salary) del(a[0]) a.pop() avg=sum(a)/len(a) return avg
average-salary-excluding-the-minimum-and-maximum-salary
[python]-runtime-31ms
user9516zM
0
1
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,180
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2771074/O(N)
class Solution: def average(self, salary: List[int]) -> float: minimum = min(salary) maximum = max(salary) salary.remove(minimum) salary.remove(maximum) return mean(salary)
average-salary-excluding-the-minimum-and-maximum-salary
O(N)
haniyeka
0
1
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,181
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2770848/Python-Simple-Solution-O(NlogN)
class Solution: def average(self, salary: List[int]) -> float: total_sum = sum(salary) salary.sort() total_sum= total_sum - salary[0]- salary[-1] return total_sum/ (len(salary)-2)
average-salary-excluding-the-minimum-and-maximum-salary
Python Simple Solution O(NlogN)
silvestrofrisullo
0
2
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,182
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2766314/Python3-or-One-Pass-or-Easy-or-O(N)
class Solution: def average(self, salary: List[int]) -> float: min_val, max_val = float('+inf'), float('-inf') total_sum = 0 for num in salary: min_val = min(min_val, num) max_val = max(max_val, num) total_sum += num return (total_sum - min_val - max_val) / (len(salary) - 2)
average-salary-excluding-the-minimum-and-maximum-salary
Python3 | One Pass | Easy | O(N)
ivan_shelonik
0
2
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,183
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2760685/Average-of-salary-excluding-minimum-and-maximum
class Solution: def average(self, salary: List[int]) -> float: salary.sort() sum = 0 for i in range(1,len(salary) - 1): sum += salary[i] lenelem = len(salary) - 2 avg = sum / lenelem return avg
average-salary-excluding-the-minimum-and-maximum-salary
Average of salary excluding minimum and maximum
keerthikrishnakumar93
0
1
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,184
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2749929/Python3-easy-and-well-explain-solution
class Solution: def average(self, salary: List[int]) -> float: return ((sum(salary)- min(salary) - max(salary))/(len(salary)-2))
average-salary-excluding-the-minimum-and-maximum-salary
Python3 easy and well explain solution
ride-coder
0
1
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,185
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2749069/Easy-Python-Solution-using-List
class Solution: def average(self, salary: List[int]) -> float: salary.remove(min(salary)) salary.remove(max(salary)) return sum(salary)/len(salary)
average-salary-excluding-the-minimum-and-maximum-salary
Easy Python Solution using List
vivekrajyaguru
0
2
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,186
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2724381/95-efficient
class Solution: def average(self, salary: List[int]) -> float: salary.remove(max(salary)) salary.remove(min(salary)) return sum(salary)/len(salary)
average-salary-excluding-the-minimum-and-maximum-salary
95% efficient
mdfaisalabdullah
0
6
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,187
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2716604/I'm-learning-Python-any-suggestions-for-better-time
class Solution: def average(self, salary: List[int]) -> float: total = 0 divide= 0 salary.sort() salary.pop(0) salary.pop(-1) for numbers in salary: total = total + numbers divide += 1 average = total / divide return average
average-salary-excluding-the-minimum-and-maximum-salary
I'm learning Python, any suggestions for better time?
imrlycl3508
0
4
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,188
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2689606/Python-One-Liner
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary) - (max(salary) + min(salary))) / (len(salary) - 2)
average-salary-excluding-the-minimum-and-maximum-salary
Python One Liner
anandanshul001
0
9
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,189
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2661359/I-was-surprised-not-to-see-this-version-python-solution.-not-the-fastest-but-very-straightforward
class Solution: def average(self, salary: List[int]) -> float: salary.remove(max(salary)) salary.remove(min(salary)) return sum(salary) / len(salary)
average-salary-excluding-the-minimum-and-maximum-salary
I was surprised not to see this version python solution. not the fastest, but very straightforward
JustARendomGuy
0
4
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,190
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2657352/Python3-or-Simple
class Solution: def average(self, salary: List[int]) -> float: salary.sort() s = salary[1:-1] length = len(s) total_salary = sum(s) return (total_salary)/(length)
average-salary-excluding-the-minimum-and-maximum-salary
Python3 | Simple
AnzheYuan1217
0
46
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,191
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2654922/Easy-Python-Solution-or-One-Line
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary) - max(salary) - min(salary))/(len(salary)-2)
average-salary-excluding-the-minimum-and-maximum-salary
🐍 Easy Python Solution | One Line ⭐
kanvi26
0
2
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,192
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2654815/Python-or-Simple-minmax-solution-or-O(n)
class Solution: def average(self, salary: List[int]) -> float: mi = min(salary) mx = max(salary) s, count = 0, 0 for sal in salary: if sal != mi and sal != mx: s += sal count += 1 return round(s / count, 5)
average-salary-excluding-the-minimum-and-maximum-salary
Python | Simple min/max solution | O(n)
LordVader1
0
30
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,193
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2643542/very-easy-approach!
class Solution: def average(self, salary: List[int]) -> float: salary.sort() salary.pop(0) salary.pop(-1) x = sum(salary) return (x/len(salary))
average-salary-excluding-the-minimum-and-maximum-salary
very easy approach!
sanjeevpathak
0
2
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,194
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2625900/Simple-Python-Solution-or-2-liner
class Solution: def average(self, salary: List[int]) -> float: salary.sort() return (sum(salary)-salary[0]-salary[-1])/(len(salary)-2)
average-salary-excluding-the-minimum-and-maximum-salary
Simple Python Solution | 2-liner
Siddharth_singh
0
25
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,195
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2614123/A-O(n)-time-O(1)-space-approach-in-one-loop
class Solution: def average(self, salary: List[int]) -> float: minimum, maximum, total = (10 ** 6) + 1, 0, 0 for pay in salary: total += pay if pay < minimum: minimum = pay if pay > maximum: maximum = pay return (total - minimum - maximum) / (len(salary) - 2)
average-salary-excluding-the-minimum-and-maximum-salary
A O(n) time, O(1) space approach in one loop
kcstar
0
16
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,196
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2576100/Python-easy-three-line-solution
class Solution: def average(self, salary: List[int]) -> float: salary.remove(max(salary)) salary.remove(min(salary)) return sum(salary)/len(salary)
average-salary-excluding-the-minimum-and-maximum-salary
Python easy three line solution
mjk22071998
0
48
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,197
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2504929/Python-A-single-Pass-Not-multiple-passes
class Solution: def average(self, salary: List[int]) -> float: # make one pass through the array and track sum # as well as minmum and maximum summed = 0 maxed = 0 mined = 1000001 counter = 0 # this only needs a single pass # whereas min, max, sum all need separate passes for sal in salary: counter += 1 summed += sal maxed = max(sal, maxed) mined = min(sal, mined) return (summed - mined - maxed)/(counter - 2)
average-salary-excluding-the-minimum-and-maximum-salary
[Python] - A single Pass - Not multiple passes
Lucew
0
42
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,198
https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/discuss/2473258/Python-Sum-%2B-MinMax-%2B-Len-solution.
class Solution: def average(self, salary: List[int]) -> float: return (sum(salary) - max(salary) - min(salary)) / (len(salary) - 2)
average-salary-excluding-the-minimum-and-maximum-salary
[Python] Sum + Min/Max + Len solution.
duynl
0
34
average salary excluding the minimum and maximum salary
1,491
0.627
Easy
22,199