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/minimum-time-to-complete-trips/discuss/1802745/Python-solution-using-Binary-Search | class Solution:
def minimumTime(self, time: List[int], totalTrips: int) -> int:
if len(time) == 1:
return totalTrips * time[0]
def compute(arr, number):
res = 0
for i in arr:
if number >= i:
res += number // i
... | minimum-time-to-complete-trips | Python solution using Binary Search | bianrui0315 | 0 | 14 | minimum time to complete trips | 2,187 | 0.32 | Medium | 30,400 |
https://leetcode.com/problems/minimum-time-to-complete-trips/discuss/1802659/Python3-or-binary-search | class Solution:
def minimumTime(self, time: List[int], totalTrips: int) -> int:
def feasible(timeAllot):
'''
This function find the number of trips taken by the buses for the given time
'''
totalCount = 0
for var in time:
totalCount+=timeAllot//var
... | minimum-time-to-complete-trips | Python3 | binary search | Anilchouhan181 | 0 | 24 | minimum time to complete trips | 2,187 | 0.32 | Medium | 30,401 |
https://leetcode.com/problems/minimum-time-to-complete-trips/discuss/1802559/Python3-O(N-log-T2)-Binary-Search-on-Solution-Space-(explained) | class Solution:
def maxtrip(self, time):
trips = 0
for t in (k for k in self.counter.keys() if k <= time):
trips += self.counter[t] * (time // t)
return trips
def minimumTime(self, time: List[int], totalTrips: int) -> int:
self.counter = Counter(time)
... | minimum-time-to-complete-trips | [Python3] O(N log T^2) Binary Search on Solution Space (explained) | dwschrute | 0 | 20 | minimum time to complete trips | 2,187 | 0.32 | Medium | 30,402 |
https://leetcode.com/problems/minimum-time-to-complete-trips/discuss/1802521/PYTHON3-SIMPLE-BINARY-SEARCH | class Solution:
def minimumTime(self, time: List[int], totalTrips: int) -> int:
def condition(mid,nums,totalTrips):
ans=0
for num in nums:
ans+=mid//num
if ans>=totalTrips:
return True
return False
lo=0 #minimum... | minimum-time-to-complete-trips | [PYTHON3] SIMPLE BINARY SEARCH | _shubham28 | 0 | 15 | minimum time to complete trips | 2,187 | 0.32 | Medium | 30,403 |
https://leetcode.com/problems/minimum-time-to-finish-the-race/discuss/1803014/Python-DP-with-pre-treatment-to-reduce-time-complexity | class Solution:
def minimumFinishTime(self, tires: List[List[int]], changeTime: int, numLaps: int) -> int:
tires.sort()
newTires = []
minTime = [changeTime*(i-1) + tires[0][0]*i for i in range(numLaps+1)]
minTime[0] = 0
maxi = 0
for f,r in tires:
if not ne... | minimum-time-to-finish-the-race | [Python] DP with pre-treatment to reduce time complexity | wssx349 | 3 | 226 | minimum time to finish the race | 2,188 | 0.419 | Hard | 30,404 |
https://leetcode.com/problems/minimum-time-to-finish-the-race/discuss/1802676/Python3-dp | class Solution:
def minimumFinishTime(self, tires: List[List[int]], changeTime: int, numLaps: int) -> int:
init = [inf] * 20
for f, r in tires:
prefix = term = f
for i in range(20):
init[i] = min(init[i], prefix)
term *= r
if ... | minimum-time-to-finish-the-race | [Python3] dp | ye15 | 1 | 214 | minimum time to finish the race | 2,188 | 0.419 | Hard | 30,405 |
https://leetcode.com/problems/minimum-time-to-finish-the-race/discuss/1804202/Python-3-Geometric-progression-sum-and-DP-(hint-solution)-with-comments-(Optimization-needed) | class Solution:
def minimumFinishTime(self, tires: List[List[int]], ct: int, laps: int) -> int:
t_nochange = defaultdict(lambda: float('inf'))
for f, r in tires:
# calculate how many laps could go without changing tires
# f * pow(r, p) <= f + ct
p = math.... | minimum-time-to-finish-the-race | [Python 3] Geometric progression sum and DP (hint solution) with comments (Optimization needed) | chestnut890123 | 0 | 92 | minimum time to finish the race | 2,188 | 0.419 | Hard | 30,406 |
https://leetcode.com/problems/minimum-time-to-finish-the-race/discuss/1802856/Python3-Dynamic-Programming | class Solution:
def minimumFinishTime(self, tires: List[List[int]], changeTime: int, numLaps: int) -> int:
@cache
def lapTime(tire,x):
f,r = tire
return f*(r**(x-1))
best_laps = {}
for tire in tires:
tire = tuple(tire)
... | minimum-time-to-finish-the-race | [Python3] Dynamic Programming | Rainyforest | 0 | 81 | minimum time to finish the race | 2,188 | 0.419 | Hard | 30,407 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1924231/Python-Multiple-Solutions-%2B-One-Liners-or-Clean-and-Simple | class Solution:
def mostFrequent(self, nums, key):
counts = {}
for i in range(1,len(nums)):
if nums[i-1]==key:
if nums[i] not in counts: counts[nums[i]] = 1
else: counts[nums[i]] += 1
return max(counts, key=counts.get) | most-frequent-number-following-key-in-an-array | Python - Multiple Solutions + One-Liners | Clean and Simple | domthedeveloper | 4 | 214 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,408 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1924231/Python-Multiple-Solutions-%2B-One-Liners-or-Clean-and-Simple | class Solution:
def mostFrequent(self, nums, key):
arr = [nums[i] for i in range(1,len(nums)) if nums[i-1]==key]
c = Counter(arr)
return max(c, key=c.get) | most-frequent-number-following-key-in-an-array | Python - Multiple Solutions + One-Liners | Clean and Simple | domthedeveloper | 4 | 214 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,409 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1924231/Python-Multiple-Solutions-%2B-One-Liners-or-Clean-and-Simple | class Solution:
def mostFrequent(self, nums, key):
return max(c := Counter([nums[i] for i in range(1,len(nums)) if nums[i-1]==key]), key=c.get) | most-frequent-number-following-key-in-an-array | Python - Multiple Solutions + One-Liners | Clean and Simple | domthedeveloper | 4 | 214 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,410 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1924231/Python-Multiple-Solutions-%2B-One-Liners-or-Clean-and-Simple | class Solution:
def mostFrequent(self, nums, key):
return mode(nums[i] for i in range(1,len(nums)) if nums[i-1]==key) | most-frequent-number-following-key-in-an-array | Python - Multiple Solutions + One-Liners | Clean and Simple | domthedeveloper | 4 | 214 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,411 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1924231/Python-Multiple-Solutions-%2B-One-Liners-or-Clean-and-Simple | class Solution:
def mostFrequent(self, nums, key):
return mode(b for a, b in pairwise(nums) if a == key) | most-frequent-number-following-key-in-an-array | Python - Multiple Solutions + One-Liners | Clean and Simple | domthedeveloper | 4 | 214 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,412 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1914928/Python3-Dictionary-Solution-With-Explanation | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
m = {}
for i in range(len(nums) - 1):
if nums[i] == key:
if nums[i + 1] in m:
m[nums[i + 1]] += 1
else:
m[nums[i + 1]] = 1
#... | most-frequent-number-following-key-in-an-array | Python3 Dictionary Solution With Explanation | Hejita | 1 | 110 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,413 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1822593/Python | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
c = defaultdict(int)
max_count = 0
max_target = 0
for i in range(1, len(nums)):
if nums[i-1] == key:
c[nums[i]] += 1
if c[nums[i]] > max_count:
m... | most-frequent-number-following-key-in-an-array | Python | blue_sky5 | 1 | 49 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,414 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2833207/Python-easy-code-solution-or-Runtime-beats%3A-98 | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
a = []
for i in range(len(nums)):
if(i != len(nums)-1):
if(nums[i] == key):
a.append(nums[i+1])
c = Counter(a)
print(c)
ans = max(c,key = c.get)
r... | most-frequent-number-following-key-in-an-array | Python easy code solution | Runtime beats: 98% | anshu71 | 0 | 2 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,415 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2807798/O(n%2Bm)-87ms-python | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
uniqueInts = max(nums)
length = len(nums)
freqs = [0 for i in range(uniqueInts+1)] #count every unique number
#Goto each target
for i in range(len(nums)): #iterate the index of inputlist
if... | most-frequent-number-following-key-in-an-array | O(n+m) 87ms python | lucasscodes | 0 | 2 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,416 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2763799/Most-Frequent-Number-Following-Key-In-an-Array-or-Using-Dictionaries-or-Python | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
d={}
i=0
while(i<len(nums)-1):
if nums[i]==key:
target=nums[i+1]
count=0
for j in range(i+1,len(nums)):
if nums[j]==target:
... | most-frequent-number-following-key-in-an-array | Most Frequent Number Following Key In an Array | Using Dictionaries | Python | saptarishimondal | 0 | 1 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,417 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2502510/Simple-solution-using-dictionary-and-lambda-function-in-Python | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
freq = {}
for i in range(len(nums)):
val = nums[i]
if val == key and i + 1 < len(nums):
val2 = nums[i + 1]
freq[val2] = 1 + freq.get(val2, 0)
return max(freq, key... | most-frequent-number-following-key-in-an-array | Simple solution using dictionary and lambda function in Python | ankurbhambri | 0 | 16 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,418 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2384958/Python3-Easy-hashmap-Faster-than-90 | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
nums=nums + [-1]
c={}
l=len(nums)
max_=-1
ans=-1
for i in range(l-1):
if nums[i]==key:
if nums[i+1] in c:
c[nums[i+1]]+=1
else:
... | most-frequent-number-following-key-in-an-array | [Python3] Easy hashmap- Faster than 90% | sunakshi132 | 0 | 26 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,419 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2332476/Easy-Hashmap-Solution | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
hashMap = collections.defaultdict(int)
key_found=False
for idx, el in enumerate(nums):
# Check if key is already found and the target value is key and is contiguous
if key_found and nums[idx-1] ... | most-frequent-number-following-key-in-an-array | Easy Hashmap Solution | yashchandani98 | 0 | 14 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,420 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2252836/Python-Short-and-Simple | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
arr = [nums[i+1] for i in range(len(nums)-1) if nums[i] == key]
d = Counter(arr)
return max(d, key = d.get) ## Return the Key with Maximum Value | most-frequent-number-following-key-in-an-array | Python Short and Simple | theReal007 | 0 | 18 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,421 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2217803/Python-Simple-Solution-or-Beats-speed-97 | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
d = {}
l = len(nums)
m = ind = 0
for i in range(l - 1):
if nums[i] == key:
cur_n = nums[i + 1]
if cur_n in d:
d[cur_n] += 1
else:
... | most-frequent-number-following-key-in-an-array | Python Simple Solution | Beats speed 97% | Bec1l | 0 | 43 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,422 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/2152345/Python3-freq-table | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
freq = Counter(x for i, x in enumerate(nums) if i and nums[i-1] == key)
return max(freq, key=freq.get) | most-frequent-number-following-key-in-an-array | [Python3] freq table | ye15 | 0 | 29 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,423 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1979234/Python-Easy-To-Understand-Solution | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
def most_frequent(List):
return max(set(List), key = List.count)
amt_following = 0
amt_showed = []
for i in range(len(nums)):
if nums[i] == key:
if i <= len(nums)-2... | most-frequent-number-following-key-in-an-array | Python Easy To Understand Solution | KirillMcQ | 0 | 74 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,424 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1944124/Python-dollarolution | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
d = {}
for i in range(1,len(nums)):
if nums[i-1] == key:
if nums[i] not in d:
d[nums[i]] = 1
else:
d[nums[i]] += 1
return max(d, key=d... | most-frequent-number-following-key-in-an-array | Python $olution | AakRay | 0 | 31 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,425 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1860222/python-simple-hashmap-solution | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
n = len(nums)
count = defaultdict(int)
maxcount = 0
for i in range(n-1):
if nums[i] == key:
count[nums[i+1]] += 1
maxcount = max(maxcount, count[nums[i+1]])
... | most-frequent-number-following-key-in-an-array | python simple hashmap solution | byuns9334 | 0 | 44 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,426 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1843877/Python-(Simple-approach-and-Beginner-friendly) | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
dict = {}
for i in range(len(nums)-1):
if nums[i] == key:
if nums[i+1] not in dict:
dict[nums[i+1]]=1
else:
dict[nums[i+1]]+=1
return ... | most-frequent-number-following-key-in-an-array | Python (Simple approach and Beginner-friendly) | vishvavariya | 0 | 60 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,427 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1825271/Python-Simply-follow-the-topic | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
targets = []
for i in range(1, len(nums)):
if nums[i - 1] == key:
targets.append(nums[i])
if len(targets) == 1:
return targets[0]
m = collectio... | most-frequent-number-following-key-in-an-array | [Python] Simply follow the topic | casshsu | 0 | 29 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,428 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1825271/Python-Simply-follow-the-topic | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
c = Counter()
for i in range(1, len(nums)):
if nums[i - 1] == key:
c[nums[i]] += 1
return c.most_common(1)[0][0] | most-frequent-number-following-key-in-an-array | [Python] Simply follow the topic | casshsu | 0 | 29 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,429 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1822423/An-intuitive-approach-simple | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
n = len(nums)
dic = {}
for i in range(n-1):
if nums[i] == key:
if nums[i+1] not in dic:
dic[nums[i+1]] = 1
else:
dic[nums[i+1]] += 1
#print(dic)
val = max(dic.values())
#print(val)
for key in dic:
if dic[ke... | most-frequent-number-following-key-in-an-array | An intuitive approach [simple] | nandanabhishek | 0 | 43 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,430 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1822398/python-3-simple-hash-map-solution | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
count = collections.Counter()
max_count = 0
target = -1
for i in range(len(nums) - 1):
if nums[i] != key:
continue
count[nums[i + 1]] += 1
... | most-frequent-number-following-key-in-an-array | python 3, simple hash map solution | dereky4 | 0 | 33 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,431 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1822358/Python3-or-Simple-solution-using-max-function-with-key-and-an-extra-array-to-keep-track-of-targets | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
target = []
for i in range(len(nums) - 1):
if nums[i] == key:
target.append(nums[i+1])
return max(target, key=target.count)
# Time Complexity: O(n)
# Space Complex... | most-frequent-number-following-key-in-an-array | Python3 | Simple solution using max function with key and an extra array to keep track of targets | HunkWhoCodes | 0 | 22 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,432 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1822275/python3-hashmap | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
hashmap = collections.defaultdict(int)
for a, b in zip(nums, nums[1:]):
if a == key:
hashmap[b] += 1
max_val = max(val for val in hashmap.values())
... | most-frequent-number-following-key-in-an-array | python3, hashmap | emersonexus | 0 | 20 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,433 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1822127/Python-hashmap | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
d = defaultdict(int)
left, right = 0, len(nums)-1
while left < right:
if nums[left] == key:
d[nums[left+1]] += 1
left += 1
return max(d, key=d.get) | most-frequent-number-following-key-in-an-array | Python hashmap | Rush_P | 0 | 28 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,434 |
https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/discuss/1821973/Python-3-(70ms)-or-Dictionary-Solution-or-Easy-to-Understand | class Solution:
def mostFrequent(self, nums: List[int], key: int) -> int:
d={}
for i in range(len(nums)-1):
if nums[i]==key:
if nums[i+1] in d:
d[nums[i+1]]+=1
else:
d[nums[i+1]]=1
m=-1
for j in d:
... | most-frequent-number-following-key-in-an-array | Python 3 (70ms) | Dictionary Solution | Easy to Understand | MrShobhit | 0 | 54 | most frequent number following key in an array | 2,190 | 0.605 | Easy | 30,435 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1822244/Sorted-Lambda | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
@cache
def convert(i: int):
res, pow10 = 0, 1
while i:
res += pow10 * mapping[i % 10]
i //= 10
pow10 *= 10
return res
r... | sort-the-jumbled-numbers | Sorted Lambda | votrubac | 8 | 869 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,436 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1822468/Python-10-Liner-Solution | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
res = []
for num in nums:
ans = ""
for char in str(num):
ans += str(mapping[int(char)])
res.append(int(ans))
final = list(zip(nums, res))
final = sorted(final, key=lambda x: x[1])
return [tup[0] for tup in f... | sort-the-jumbled-numbers | [Python] - 10 Liner Solution ✔ | leet_satyam | 2 | 54 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,437 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1822287/python-1-line | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
return sorted(nums, key = lambda x: int("".join([str(mapping[int(digit)]) for digit in str(x)]))) | sort-the-jumbled-numbers | python 1-line | emersonexus | 2 | 97 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,438 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1828757/Python-2-lines.-Does-using-strings-count-as-cheating | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
m = { str(i): str(v) for i, v in enumerate(mapping) }
def mapFunc(n):
return int(''.join(m[i] for i in str(n)))
return sorted(nums, key=mapFunc) | sort-the-jumbled-numbers | Python 2 lines. Does using strings count as cheating? | SmittyWerbenjagermanjensen | 1 | 73 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,439 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1828757/Python-2-lines.-Does-using-strings-count-as-cheating | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
m = { str(i): str(v) for i, v in enumerate(mapping) }
return sorted(nums, key=lambda x: int(''.join(m[i] for i in str(x)))) | sort-the-jumbled-numbers | Python 2 lines. Does using strings count as cheating? | SmittyWerbenjagermanjensen | 1 | 73 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,440 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1822078/Python-3%3A-Easy-Solution | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
h = {}
ans = []
for num in nums:
res = 0
for i in str(num):
val = mapping[int(i)]
res = res*10 + val
ans.append((num,res))
ans.... | sort-the-jumbled-numbers | Python 3: Easy Solution | deleted_user | 1 | 20 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,441 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1822072/Python-3-Sorting-using-key-function-in-Python | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
ans = []
def compare(num):
temp = ""
for digit in str(num):
temp += str(mapping[int(digit)])
return int(temp)
return sorted(nums, key=compare) | sort-the-jumbled-numbers | [Python 3] Sorting using key function in Python | hari19041 | 1 | 49 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,442 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/2777340/Python-3-3-Lines | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
md={str(i):str(mapping[i]) for i in range(len(mapping))}
md2=[[i,int(''.join([md[j] for j in str(i)]))] for i in nums]
return [i[0] for i in sorted(md2,key=lambda x:x[1])] | sort-the-jumbled-numbers | Python 3-3 Lines | Burak1069711851 | 0 | 2 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,443 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/2152354/Python3-1-line | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
return sorted(nums, key=lambda x: int(''.join(str(mapping[int(d)]) for d in str(x)))) | sort-the-jumbled-numbers | [Python3] 1-line | ye15 | 0 | 24 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,444 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1927733/python-3-oror-simple-solution | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
nums.sort(key=lambda num: self.value(num, mapping))
return nums
def value(self, num, mapping):
if num == 0:
return mapping[0]
res, m = 0, 1
while num:
re... | sort-the-jumbled-numbers | python 3 || simple solution | dereky4 | 0 | 66 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,445 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1828027/Sort-tuples-66-speed | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
mapping = [str(i) for i in mapping]
return [tpl[2] for tpl in sorted((int("".join(mapping[int(c)]
for c in str(n))), i, n)
... | sort-the-jumbled-numbers | Sort tuples, 66% speed | EvgenySH | 0 | 14 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,446 |
https://leetcode.com/problems/sort-the-jumbled-numbers/discuss/1822122/Python-sort-list-of-tuples | class Solution:
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
def getMappedNum(num):
s = str(num)
mappedNum = ""
for c in s:
mappedNum = mappedNum + str(mapping[int(c)])
return int(mappedNum)
sortedNums = []
... | sort-the-jumbled-numbers | Python sort list of tuples | Rush_P | 0 | 25 | sort the jumbled numbers | 2,191 | 0.453 | Medium | 30,447 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/2333862/Python3-or-Solved-using-Topo-Sort(Kahn-Algo)-with-Queue(BFS) | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
#Use Kahn's algorithm of toposort using a queue and bfs!
graph = [[] for _ in range(n)]
indegrees = [0] * n
#Time: O(n^2)
#Space: O(n^2 + n + n) -> O(n^2)
#1st... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | Python3 | Solved using Topo Sort(Kahn Algo) with Queue(BFS) | JOON1234 | 4 | 169 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,448 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/1822118/Python-3-Reverse-direction-and-Find-all-Children | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
ans = [[] for _ in range(n)]
graph = defaultdict(list)
for f, t in edges:
graph[t].append(f)
memo = defaultdict(list)
def dfs(src):
if src in m... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | [Python 3] Reverse direction and Find all Children | hari19041 | 2 | 112 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,449 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/1823284/Python-3-Topological-sort-via-BFS | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
# Topological sort with BFS (Kahn's algorithm)
# Similar to LC 207 (Course Schedule), LC 210 (Course Schedule II)
graph = [[] for _ in range(n)]
inDegree = [0] * n
for edge in edges:
... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | Python 3 Topological sort via BFS | xil899 | 1 | 106 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,450 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/2774441/Topological-sort-Python-N2 | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
retList = [[] for i in range(n) ]
graph = collections.defaultdict(list)
indegree = [0] * n
topologicalSort = []
# Build graph and calculate indegree
for one,two in edge... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | Topological sort Python N^2 | Sarthaksin1857 | 0 | 16 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,451 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/2502761/Python-Simple-Topological-Sort-Solution | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
indeg, graph = [0]*n, defaultdict(list)
for u, v in edges:
graph[u].append(v)
indeg[v] += 1
queue, res = deque([i for i in range(n) if indeg[i] == 0]), [set() for _... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | [Python] Simple Topological Sort Solution | Saksham003 | 0 | 55 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,452 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/2152396/Python3-Kahn's-algo | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
graph = [[] for _ in range(n)]
indeg = [0]*n
for u, v in edges:
graph[u].append(v)
indeg[v] += 1
ans = [set() for _ in range(n)]
queue = deque([u for u in rang... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | [Python3] Kahn's algo | ye15 | 0 | 26 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,453 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/1923587/Python3-or-Simple-DFS-from-Every-Node-O(N2) | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
self.ans=[[] for i in range(n)]
adj=[[] for i in range(n)]
hset=set([tuple(i) for i in edges])
for i,j in edges:
adj[i].append(j)
adj[j].append(i)
self.vis=set()... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | [Python3] | Simple DFS from Every Node O(N^2) | swapnilsingh421 | 0 | 52 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,454 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/1830511/Dictionary-of-ancestors-76-speed | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
ancestors = defaultdict(set)
for parent, child in edges:
ancestors[child].add(parent)
ans = [set() for _ in range(n)]
for i in range(n):
if i not in ancestors:
... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | Dictionary of ancestors, 76% speed | EvgenySH | 0 | 52 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,455 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/1822948/Python-3-DFS-and-Kahn's-algorithm | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
ans = [set() for _ in range(n)]
g = defaultdict(set)
deg = defaultdict(int)
for u, v in edges:
g[u].add(v)
deg[v] += 1
def df... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | [Python 3] DFS and Kahn's algorithm | chestnut890123 | 0 | 65 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,456 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/1822948/Python-3-DFS-and-Kahn's-algorithm | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
ans = [set() for _ in range(n)]
g = defaultdict(set)
deg = defaultdict(int)
for u, v in edges:
g[u].add(v)
deg[v] += 1
starts = [i for... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | [Python 3] DFS and Kahn's algorithm | chestnut890123 | 0 | 65 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,457 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/1822353/Python-or-Easy-Understanding-or-DFS-and-caching | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
parents = defaultdict(set)
for frm, to in edges: parents[to].add(frm)
@cache
def find_ancestor(n):
if n not in parents: return set()
res = set()
... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | Python | Easy Understanding | DFS and caching | rbhandu | 0 | 31 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,458 |
https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/discuss/1822304/python-hashmap-of-parents | class Solution:
def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:
result = []
hashmap = collections.defaultdict(set)
parent = collections.defaultdict(set)
# indegree = collections.defaultdict(int)
for a, b in edges:
... | all-ancestors-of-a-node-in-a-directed-acyclic-graph | python, hashmap of parents | emersonexus | 0 | 39 | all ancestors of a node in a directed acyclic graph | 2,192 | 0.503 | Medium | 30,459 |
https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/discuss/2152484/Python3-peel-the-string | class Solution:
def minMovesToMakePalindrome(self, s: str) -> int:
ans = 0
while len(s) > 2:
lo = s.find(s[-1])
hi = s.rfind(s[0])
if lo < len(s)-hi-1:
ans += lo
s = s[:lo] + s[lo+1:-1]
else:
ans += ... | minimum-number-of-moves-to-make-palindrome | [Python3] peel the string | ye15 | 1 | 614 | minimum number of moves to make palindrome | 2,193 | 0.514 | Hard | 30,460 |
https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/discuss/2812340/Python-%2B-2-pointers-%2B-Explanation. | class Solution:
def minMovesToMakePalindrome(self, s: str) -> int:
# At each point, we look at the first and the last elements
# if they are the same, then we skip them, else we find
# another element in the string that matches the left
# element and then we make the necessary swaps ... | minimum-number-of-moves-to-make-palindrome | Python + 2 pointers + Explanation. | rasnouk | 0 | 7 | minimum number of moves to make palindrome | 2,193 | 0.514 | Hard | 30,461 |
https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/discuss/2800512/Easy-to-Understand-2-Pointer-Solution | class Solution:
def minMovesToMakePalindrome(self, s: str) -> int:
'''
Intuition: Start on the outer corners, moving in from left and right, and do min swaps to make them the same.
Spacetime: O(n)
Runtime: O(n^2)
'''
i, j = 0, len(s) - 1
sArr = l... | minimum-number-of-moves-to-make-palindrome | Easy to Understand 2-Pointer Solution | nickpavini | 0 | 4 | minimum number of moves to make palindrome | 2,193 | 0.514 | Hard | 30,462 |
https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/discuss/2567960/Python-Greedy-2-pointer | class Solution:
def minMovesToMakePalindrome(self, s: str) -> int:
s = list(s) #makes it easy for assignment op
res = 0
left, right = 0, len(s) - 1
while left < right:
l, r = left, right
#find matching char
while s[l] != s[r]:
r -= 1
# if index dont match then swap
if l != r:
# swap ... | minimum-number-of-moves-to-make-palindrome | Python Greedy 2 pointer | shubhamnishad25 | 0 | 222 | minimum number of moves to make palindrome | 2,193 | 0.514 | Hard | 30,463 |
https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/discuss/1831236/Removing-pairs-70-speed | class Solution:
def minMovesToMakePalindrome(self, s: str) -> int:
ans = 0
def remove_edges(current: str) -> str:
nonlocal ans
left, right = dict(), dict()
len_c1 = len(current) - 1
for i, c in enumerate(current):
if c in right and i !... | minimum-number-of-moves-to-make-palindrome | Removing pairs, 70% speed | EvgenySH | 0 | 240 | minimum number of moves to make palindrome | 2,193 | 0.514 | Hard | 30,464 |
https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/discuss/1826026/python-3%3A-basic-1000ms | class Solution:
@lru_cache(None)
def minMovesToMakePalindrome(self, s: str) -> int:
n = len(s)
if n<=1:
return 0
if s[0] == s[-1]:
return self.minMovesToMakePalindrome(s[1:-1])
i = 1
while s[i]!=s[-1]:
i+=1
j = n - 2
whi... | minimum-number-of-moves-to-make-palindrome | python 3: basic 1000ms | akbc | 0 | 133 | minimum number of moves to make palindrome | 2,193 | 0.514 | Hard | 30,465 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1823607/Python3-1-line | class Solution:
def cellsInRange(self, s: str) -> List[str]:
return [chr(c)+str(r) for c in range(ord(s[0]), ord(s[3])+1) for r in range(int(s[1]), int(s[4])+1)] | cells-in-a-range-on-an-excel-sheet | [Python3] 1-line | ye15 | 7 | 368 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,466 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2369701/Simple-Python3-or-NO-ord()-NO-chr() | class Solution:
def cellsInRange(self, s: str) -> List[str]:
start, end = s.split(':')
start_letter, start_num = start[0], int(start[-1])
end_letter, end_num = end[0], int(end[1])
alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
alphabet_slice = \
alphabet[alphabet.i... | cells-in-a-range-on-an-excel-sheet | Simple Python3 | NO ord(), NO chr() | Sergei_Gusev | 2 | 87 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,467 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1823610/Beginner-Friendly-Python-Solution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
row1 = int(s[1])
row2 = int(s[4])
col1 = ord(s[0]) # To get their Unicode values
col2 = ord(s[3]) # To get their Unicode values
res = []
# Since we are asked to sort the answer list first column and then row... | cells-in-a-range-on-an-excel-sheet | Beginner Friendly Python Solution | anCoderr | 2 | 187 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,468 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1823610/Beginner-Friendly-Python-Solution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
return [f"{chr(i)}{j}" for i in range(ord(s[0]), ord(s[3])+1) for j in range(int(s[1]), int(s[4])+1)] | cells-in-a-range-on-an-excel-sheet | Beginner Friendly Python Solution | anCoderr | 2 | 187 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,469 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2823458/Simplest-Detailed-Approach-in-Python3 | class Solution:
def cellsInRange(self, s: str) -> List[str]:
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# Rows
r1 = int(s[1])
r2 = int(s[-1])
# Columns
c1 = s[0]
c2 = s[-2]
op = []
for col in range(alpha.index(c1), alpha.index(c2)+1):
... | cells-in-a-range-on-an-excel-sheet | Simplest Detailed Approach in Python3 | kschaitanya2001 | 1 | 28 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,470 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1944120/Python-dollarolution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
v = []
for i in range(ord(s[0]),ord(s[3])+1):
for j in range(int(s[1]),int(s[4])+1):
v.append(chr(i)+str(j))
return v | cells-in-a-range-on-an-excel-sheet | Python $olution | AakRay | 1 | 81 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,471 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1937740/Python-Using-For-Loops-Faster-Than-94 | class Solution:
def cellsInRange(self, s: str) -> List[str]:
res = []
for letter in range(ord(s[0]), ord(s[3]) + 1, 1):
for i in range(int(s[1]), int(s[-1]) + 1):
res.append(chr(letter) + str(i))
return res | cells-in-a-range-on-an-excel-sheet | Python Using For Loops, Faster Than 94% | Hejita | 1 | 105 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,472 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1868179/Python3-Simple-two-loops-O(n)-time-O(1)-space | class Solution:
def cellsInRange(self, s: str) -> List[str]:
alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z"]
res = []
start = alphabet.index(s[0])
... | cells-in-a-range-on-an-excel-sheet | [Python3] Simple two loops - O(n) time, O(1) space | hanelios | 1 | 66 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,473 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1856136/1-Line-Python-Solution-oror-80-Faster-oror-Memory-less-than-25 | class Solution:
def cellsInRange(self, s: str) -> List[str]:
return [chr(i)+str(j) for i in range(ord(s[0]),ord(s[3])+1) for j in range(int(s[1]),int(s[4])+1)] | cells-in-a-range-on-an-excel-sheet | 1-Line Python Solution || 80% Faster || Memory less than 25% | Taha-C | 1 | 100 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,474 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2839665/Python-Dynamic-Solution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
alpha = ['A','B','C','D','E','F',
'G','H','I','J','K','L',
'M','N','O','P','Q','R',
'S','T','U','V','W','X',
'Y','Z']
r=0
end_num,start_num = int(s[-1]),int(s[1])
... | cells-in-a-range-on-an-excel-sheet | Python Dynamic Solution | ameenusyed09 | 0 | 1 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,475 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2799364/simple-solution-in-python-3-lines-of-codes | class Solution:
def cellsInRange(self, s: str) -> List[str]:
minCol, maxCol = ord(s[0]), ord(s[3])
minRow, maxRow = int(s[1]), int(s[4])
return [chr(i)+str(j) for i in range(minCol, maxCol+1) for j in range(minRow, maxRow+1)] | cells-in-a-range-on-an-excel-sheet | simple solution in python, 3 lines of codes | chj2788 | 0 | 1 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,476 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2690477/Python3-One-Liner-and-Readable-Solution | class Solution:
def cellsInRange2(self, s: str) -> List[str]:
result = []
for col in range(ord(s[0]), ord(s[3])+1):
for row in range(int(s[1]), int(s[4])+1):
result.append(f"{chr(col)}{row}")
return result
def cellsInRange(self, s: str) -> List[str]:
r... | cells-in-a-range-on-an-excel-sheet | [Python3] - One-Liner and Readable Solution | Lucew | 0 | 2 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,477 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2685441/Python-solution-beats-98-uses-string-array-as-hashmap-(comments-and-explanation-incl.) | class Solution:
def cellsInRange(self, s: str) -> List[str]:
colmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#Calculate number of rows and columns
num_rows = abs(int(s[-1])-int(s[1])) + 1
num_cols = abs(ord(s[0]) - ord(s[-2])) + 1
print(num_rows)
print(num_cols)
res = ... | cells-in-a-range-on-an-excel-sheet | Python solution beats 98%, uses string array as hashmap (comments and explanation incl.) | cat_woman | 0 | 1 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,478 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2656057/easy-fast-straightforward-solution-in-Python | class Solution:
def cellsInRange(self, s: str) -> List[str]:
s1 =(s[:2])
s2= (s[3:])
endL = ord(s2[0])
startL = ord(s1[0])
start = int(s1[1])
end = int(s2[1])
res = []
for i in range(startL, endL+1):
for j in range(start,end+1):
... | cells-in-a-range-on-an-excel-sheet | easy fast straightforward solution in Python | asamarka | 0 | 1 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,479 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2156816/Python-Solutions | class Solution:
def cellsInRange(self, s: str) -> List[str]:
return [f'{chr(i)}{j}' for i in range(ord(s[0]), ord(s[-2]) + 1) for j in range(int(s[1]), int(s[-1]) + 1)] | cells-in-a-range-on-an-excel-sheet | Python Solutions | hgalytoby | 0 | 87 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,480 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2156816/Python-Solutions | class Solution:
def cellsInRange(self, s: str) -> List[str]:
result = []
for i in range(ord(s[0]), ord(s[-2]) + 1):
for j in range(int(s[1]), int(s[-1]) + 1):
result.append(f'{chr(i)}{j}')
return result | cells-in-a-range-on-an-excel-sheet | Python Solutions | hgalytoby | 0 | 87 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,481 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2044705/using-range-and-ordinals-to-obtain-cells | class Solution:
def cellsInRange(self, s: str) -> List[str]:
res = []
c1, c2, r1, r2 = s[0], s[3], s[1], s[4]
for c in range(ord(c1), ord(c2) + 1):
c = chr(c)
for r in range(int(r1), int(r2) + 1):
res.append(f"{c}{r}")
return res | cells-in-a-range-on-an-excel-sheet | using range and ordinals to obtain cells | andrewnerdimo | 0 | 52 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,482 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2008379/Python-easy-solution-for-you! | class Solution:
def cellsInRange(self, s: str) -> List[str]:
from string import ascii_uppercase as au
mi,ma = int(s[1]),int(s[4])
fl,ll = s[0],s[3]
ans = []
for i in range(au.index(fl),au.index(ll)+1):
for j in range(mi, ma+1):
ans += [au[i]+str(j)... | cells-in-a-range-on-an-excel-sheet | Python easy solution for you! | StikS32 | 0 | 144 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,483 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/2000338/Python3-Ord-nested-loops-n**2 | class Solution:
def cellsInRange(self, s: str) -> List[str]:
alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
ans = []
start_col, end_col = str.upper(s.split(':')[0][0]), str.upper(s.split(':')[1][0])
start_row, end_row = int(s.split(':')[0][1:]), int(s.split(':')[1][1... | cells-in-a-range-on-an-excel-sheet | [Python3] - Ord, nested loops, n**2 | patefon | 0 | 29 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,484 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1972042/Easiest-and-Simplest-Python-Solution-or-100-Faster-or-Nested-Loop-Implementation | class Solution:
def cellsInRange(self, s: str) -> List[str]:
first=s.split(":")
temp=[]
low=first[0][1]
high=first[1][1]
ele=0
diff=ord(first[1][0])-ord(first[0][0])
ele=ord(first[0][0])
for i in range(0,diff+1):
while ele<=ord(first[1][0])... | cells-in-a-range-on-an-excel-sheet | Easiest & Simplest Python Solution | 100% Faster | Nested Loop Implementation | RatnaPriya | 0 | 75 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,485 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1928337/Python-3-One-Line-Solution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
return [chr(c) + str(r) for c in range(ord(s[0]), ord(s[3]) + 1) for r in range(int(s[1]), int(s[4]) + 1)] | cells-in-a-range-on-an-excel-sheet | [Python 3] One-Line Solution | terrencetang | 0 | 48 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,486 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1924308/Python-Clean-and-Simple! | class Solution:
def cellsInRange(self, s):
out = []
# separate expression into two cells
cell1, cell2 = s.split(":")
# separate cols fom rows
col1, row1 = cell1
col2, row2 = cell2
# append cells
for col in range(ord(col1), or... | cells-in-a-range-on-an-excel-sheet | Python - Clean and Simple! | domthedeveloper | 0 | 50 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,487 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1901180/Python3-simple-solution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
a,b = s.split(':')
a1,a2 = a[0],int(a[1])
b1,b2 = b[0],int(b[1])
l1 = []
ans = []
l2 = list(range(a2,b2+1))
for i in range(ord(a1.lower()),ord(b1.lower())+1):
l1.append(chr(i).upper())
... | cells-in-a-range-on-an-excel-sheet | Python3 simple solution | EklavyaJoshi | 0 | 26 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,488 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1875025/Python3-Two-Loop-With-ASCII-Code | class Solution:
def cellsInRange(self, s: str) -> List[str]:
cell_s, cell_e = s.split(":")
head_c = ord(cell_s[0]); tail_c = ord(cell_e[0])
head_r = int(cell_s[1]); tail_r = int(cell_e[1])
res = []
for c in range(head_c, tail_c+1):
for r in range(head_r, tail_r+1)... | cells-in-a-range-on-an-excel-sheet | ✔Python3 Two Loop With ASCII Code | khRay13 | 0 | 35 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,489 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1856780/Python-easy-solution-using-ord() | class Solution:
def cellsInRange(self, s: str) -> List[str]:
res = []
for i in range(ord(s[0]), ord(s[3])+1):
for j in range(int(s[1]), int(s[4])+1):
res.append(str(chr(i))+str(j))
return res | cells-in-a-range-on-an-excel-sheet | Python easy solution using ord() | alishak1999 | 0 | 39 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,490 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1856527/very-easy-understand-beginner-level-python-code | class Solution:
def cellsInRange(self, s: str) -> List[str]:
x = s.split(":")
c = []
r = []
output = []
for i in range(ord(x[0][0]),(ord(x[1][0])+1)):
c.append(chr(i))
for i in range(int(x[0][1]),(int(x[1][1])+1)):
r.append(str(i))
for ... | cells-in-a-range-on-an-excel-sheet | very easy understand beginner level python code | dakash682 | 0 | 29 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,491 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1848921/Python-Simple-Solution | class Solution:
def cellsInRange(self, s):
res=[]
for i in range(int(s[1]),int(s[4])+1):
for j in range(int(ord(s[0])),int(ord(s[3])+1)):
#conc=str(chr(j))
res.append(str(chr(j))+str(i))
return res | cells-in-a-range-on-an-excel-sheet | Python Simple Solution | sangam92 | 0 | 38 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,492 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1846772/Python3-solution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
letters = []
counter = int(s[1])
for x in range(ord(s[0]), ord(s[3])+1):
if s[1] == s[4]:
letters.append((chr(x))+ s[1])
elif s[1] < s[4]:
temp = [chr(x)] * (int(s[4]... | cells-in-a-range-on-an-excel-sheet | Python3 solution | zhivkob | 0 | 32 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,493 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1825413/Python | class Solution:
def cellsInRange(self, s: str) -> List[str]:
result = []
r_start, r_end = ord(s[1]), ord(s[4])
c_start, c_end = ord(s[0]), ord(s[3])
for c in range(c_start, c_end+1):
for r in range(r_start, r_end+1):
result.append(chr(c) + chr(r))
... | cells-in-a-range-on-an-excel-sheet | Python | blue_sky5 | 0 | 63 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,494 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1824640/Python3-Simple-Solution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
arr = s.split(":")
l_one,l_last,n_start,n_end = arr[0][0],arr[1][0],arr[0][1],arr[1][1]
result = []
for i in range(ord(l_one),ord(l_last)+1):
char = chr(i)
for j in range(int(n_start),int(n_end)+1):... | cells-in-a-range-on-an-excel-sheet | [Python3] Simple Solution | abhijeetmallick29 | 0 | 14 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,495 |
https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/discuss/1823668/Easy-to-understand-Python-solution | class Solution:
def cellsInRange(self, s: str) -> List[str]:
source, dest = s[0], s[3]
upper_bound = max(int(s[1]), int(s[4]))
start = int(s[1])
res = []
beg_cell = ord(source)
while beg_cell <= ord(dest):
for i in range(start, upper_bound + 1):
res.append(chr(beg_cell) + str(i))
beg_cell += 1
... | cells-in-a-range-on-an-excel-sheet | Easy to understand Python solution | prudentprogrammer | 0 | 46 | cells in a range on an excel sheet | 2,194 | 0.856 | Easy | 30,496 |
https://leetcode.com/problems/append-k-integers-with-minimal-sum/discuss/1823628/Python3-swap | class Solution:
def minimalKSum(self, nums: List[int], k: int) -> int:
ans = k*(k+1)//2
prev = -inf
for x in sorted(nums):
if prev < x:
if x <= k:
k += 1
ans += k - x
else: break
prev = x
... | append-k-integers-with-minimal-sum | [Python3] swap | ye15 | 10 | 495 | append k integers with minimal sum | 2,195 | 0.25 | Medium | 30,497 |
https://leetcode.com/problems/append-k-integers-with-minimal-sum/discuss/1823649/Python-Solution-using-AP-Sum-Explained | class Solution:
def minimalKSum(self, nums: List[int], k: int) -> int:
nums.sort()
res = 0
nums.insert(0, 0)
nums.append(2000000001)
n = len(nums)
for i in range(n-1):
start = nums[i] # This is the lowerbound for current iteration
end = nums[i+... | append-k-integers-with-minimal-sum | Python Solution using AP Sum Explained | anCoderr | 8 | 716 | append k integers with minimal sum | 2,195 | 0.25 | Medium | 30,498 |
https://leetcode.com/problems/append-k-integers-with-minimal-sum/discuss/1824492/Python-Explanation-oror-sort-and-add | class Solution:
def minimalKSum(self, nums: List[int], k: int) -> int:
n=len(nums)
curr=prev=0 # intialize both curr and prev
nums.sort() # sort the nums
sum=0
for i in range(n):
curr=nums[i] # make curr equal to prev
diff=curr-(prev+1)... | append-k-integers-with-minimal-sum | Python Explanation || sort and add | rushi_javiya | 6 | 177 | append k integers with minimal sum | 2,195 | 0.25 | Medium | 30,499 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.