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/check-if-two-string-arrays-are-equivalent/discuss/2539356/Python-Solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
w1=''
w2=''
for i in word1:
print(i)
w1+=i
for j in word2:
print(j)
w2+=j
if w1==w2:
return True
else:
r... | check-if-two-string-arrays-are-equivalent | Python Solution | Sneh713 | 1 | 45 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,000 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2103100/Python-One-Line-or-98.7-Efficient-or-Simple | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ("".join(word1) == "".join(word2)) | check-if-two-string-arrays-are-equivalent | Python One Line | 98.7% Efficient | Simple | nikhitamore | 1 | 83 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,001 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/1839426/Easy-Python-simple-Solution-or-Faster-than-92.20 | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
s1="".join(word1)
s2="".join(word2)
if s1==s2:
return True
else:
return False
``` | check-if-two-string-arrays-are-equivalent | Easy Python simple Solution | Faster than 92.20 % | manav023 | 1 | 70 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,002 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/1455478/Join-arrays-into-strings-99-speed | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return "".join(word1) == "".join(word2) | check-if-two-string-arrays-are-equivalent | Join arrays into strings, 99% speed | EvgenySH | 1 | 218 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,003 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/1266781/3-Lines-of-code-and-Woah!!-Python | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
wrd1,wrd2 = ''.join(word1),''.join(word2)
if wrd1 == wrd2: return True
else: return False | check-if-two-string-arrays-are-equivalent | 3 Lines of code and Woah!! Python | Yodagaz | 1 | 67 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,004 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/1236449/python3-Easy-to-understand-and-natural-approach | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
str1 = ''
for i in word1:
str1 += i
str2=''
for j in word2:
str2 += j
return str1==str2 | check-if-two-string-arrays-are-equivalent | [python3] Easy to understand and natural approach | nandanabhishek | 1 | 198 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,005 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/1136597/Python-Simple-and-Easy-To-Understand-Solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
s1="".join(word1)
s2="".join(word2)
return s1 == s2: | check-if-two-string-arrays-are-equivalent | Python Simple & Easy To Understand Solution | saurabhkhurpe | 1 | 245 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,006 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2806422/Python-Solution-easiestgreatergreatergreatergreatergreatergreater-easy | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
w="".join(word1)
x="".join(word2)
if w in x and x in w:
return True
else:
return False | check-if-two-string-arrays-are-equivalent | Python Solution easiest>>>>>> easy | shashwatyadav2002 | 0 | 1 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,007 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2781802/Easy-String-Method-Solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
s1=''.join(word1)
s2=''.join(word2)
if s1==s2:
return True
else:
return False | check-if-two-string-arrays-are-equivalent | Easy String Method Solution | SnehaGanesh | 0 | 2 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,008 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2777163/OneLiner-Python3-solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return True if("".join(word1)=="".join(word2)) else False | check-if-two-string-arrays-are-equivalent | OneLiner Python3 solution | suyog_097 | 0 | 1 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,009 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2772864/Python3-Solution-with-using-concatenation | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return "".join(word1) == "".join(word2) | check-if-two-string-arrays-are-equivalent | [Python3] Solution with using concatenation | maosipov11 | 0 | 2 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,010 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2744167/Implementation-with-generators | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
#return ''.join(word1) == ''.join(word2)
#in efficient code above
for c1, c2 in zip(self.generator(word1), self.generator(word2)):
if c1 != c2:
return False
... | check-if-two-string-arrays-are-equivalent | Implementation with generators | tammadm | 0 | 3 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,011 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2744075/Easy-Python3-solution%3A-1-condition-check-oror-O(1)-complexity-oror-beats-70-of-the-solutions | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
a = b = ""
if a.join(word1) == b.join(word2):
return True
else:
return False | check-if-two-string-arrays-are-equivalent | Easy Python3 solution: 1 condition check || O(1) complexity || beats 70% of the solutions | GNSharma | 0 | 12 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,012 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2744015/Python-1-line-code | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return''.join(word1) ==''.join(word2) | check-if-two-string-arrays-are-equivalent | Python 1 line code | kumar_anand05 | 0 | 4 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,013 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743937/PYTHON-Python-One-line-solution-oror-EASY | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return "".join(word1) == "".join(word2) | check-if-two-string-arrays-are-equivalent | [PYTHON] Python One line solution || EASY | valera_grishko | 0 | 3 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,014 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743909/1-line-Solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ''.join(word1) == ''.join(word2) | check-if-two-string-arrays-are-equivalent | 1 line Solution | user6770yv | 0 | 1 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,015 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743758/Straightforward-Pythonic-Solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
str1 = "".join(word1)
str2 = "".join(word2)
return True if str1 == str2 else False | check-if-two-string-arrays-are-equivalent | Straightforward Pythonic Solution | yaha12 | 0 | 3 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,016 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743640/Python-One-liner | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ''.join(word1) == ''.join(word2) | check-if-two-string-arrays-are-equivalent | Python One liner | vijay_2022 | 0 | 4 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,017 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743620/Solution-using-join() | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
str1 = "".join(word1)
str2 = "".join(word2)
return str1 == str2 | check-if-two-string-arrays-are-equivalent | Solution using join() | pratiklilhare | 0 | 4 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,018 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743515/Python-or-Simple-or-faster-than-95.77-or-4-lines | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
s1 = ''.join(word1)
s2=''.join(word2)
if s1==s2:
return True
return False | check-if-two-string-arrays-are-equivalent | 🔥 Python | Simple | faster than 95.77% | 4 lines ✔ | ShubhamVora1206 | 0 | 4 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,019 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743487/2-approachs-for-better-understanding-using-python | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
"""a=""
for i in word1:
a+=i
b=""
for i in word2:
b+=i
if a==b:
return True
return False
"""
print("".join(word1))
r... | check-if-two-string-arrays-are-equivalent | 2 approachs for better understanding using python | V_Bhavani_Prasad | 0 | 7 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,020 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743447/Python-or-One-Liner-or-Easy-and-Simple | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return "".join(word1) == "".join(word2) | check-if-two-string-arrays-are-equivalent | ✔ Python | One Liner | Easy and Simple | sarveshmantri200 | 0 | 3 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,021 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743242/Python-Solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
s1 = ""
s2 = ""
for i in range(len(word1)):
s1 = s1+word1[i]
for j in range(len(word2)):
s2 = s2+word2[j]
if(s1 == s2):
return True
else:
... | check-if-two-string-arrays-are-equivalent | Python Solution | yashkumarjha | 0 | 2 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,022 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743231/Python-Solution-(short-circuit-map-len-join)-oror-99.82-of-Python3-(23ms) | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return sum(map(len,word1)) == sum(map(len,word1)) and ''.join(word1) == ''.join(word2) | check-if-two-string-arrays-are-equivalent | Python Solution (short circuit, map, len, join) || 99.82% of Python3 (23ms) | MarcosReyes | 0 | 9 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,023 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743156/Python-easy-one-liner | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return "".join(word1) == "".join(word2) | check-if-two-string-arrays-are-equivalent | Python easy one liner | adangert | 0 | 4 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,024 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2743018/Python-One-liner-easy-sol. | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ''.join(word1)==''.join(word2) | check-if-two-string-arrays-are-equivalent | Python One liner, easy sol. | jps194 | 0 | 2 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,025 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2742897/Python3!-1-Line-solution. | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ''.join(word1) == ''.join(word2) | check-if-two-string-arrays-are-equivalent | 😎Python3! 1 Line solution. | aminjun | 0 | 4 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,026 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2742846/Easy-Fast-python3-python | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
s = ''
for x in word1:
s += x
a= ''
for y in word2:
a += y
if a == s:
return True
return False | check-if-two-string-arrays-are-equivalent | Easy Fast python3 - python | genaral-kg | 0 | 5 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,027 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2742785/Simple-one-liner | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return (''.join(word1) == ''.join(word2)) | check-if-two-string-arrays-are-equivalent | Simple one liner | MockingJay37 | 0 | 2 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,028 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2742651/Python-One-Liner | class Solution:
def arrayStringsAreEqual(self, w1: List[str], w2: List[str]) -> bool:
return "".join(w1) == "".join(w2) | check-if-two-string-arrays-are-equivalent | Python One Liner | SouravSingh49 | 0 | 7 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,029 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2742435/Small-improvement-to-a-naive-approach | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
i, j = 0, 0
s_i, s_j = 0, 0
s1, s2 = '', ''
while i < len(word1):
if s2[s_i:s_i + min(s_j - s_i, len(word1[i]))] != word1[i][:min(s_j - s_i, len(word1[i]))]:
... | check-if-two-string-arrays-are-equivalent | Small improvement to a naive approach | nonchalant-enthusiast | 0 | 4 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,030 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2742257/Avoids-worst-case-scenarios!!-i-guess-..-share-any-refined-codes-too | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
str1 = "".join(word1)
str2 = "".join(word2)
if len(str1) != len(str2):
return(False)
print(str1,str2)
for i in range(0,len(str1)):
print(str1[i],str2[i])
... | check-if-two-string-arrays-are-equivalent | Avoids worst case scenarios!! i guess .. share any refined codes too | tkrishnakumar30 | 0 | 2 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,031 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2742138/PYTHON-oror-ONE-LINE-SOLUTION-oror-93-FASTER-CODE | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ''.join(word1) == ''.join(word2) | check-if-two-string-arrays-are-equivalent | PYTHON || ONE LINE SOLUTION || 93% FASTER CODE | balbinilya | 0 | 3 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,032 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2742073/Python-oror-three-lines-oror | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
s1,s2= "",""
for i in word1: s1 = s1 + i
for i in word2: s2 = s2 + i
return s1==s2 | check-if-two-string-arrays-are-equivalent | ✅ Python || three lines || | Marie-99 | 0 | 7 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,033 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741975/Generate-Yield-Simple-Approach-or-Python | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
for c1, c2 in zip(self.charWord(word1),self.charWord(word2)):
if c1 != c2:
return False
return True
def charWord(self,wordList):
for segment in wordList:
... | check-if-two-string-arrays-are-equivalent | Generate - Yield Simple Approach | Python | Abhi_-_- | 0 | 7 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,034 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741975/Generate-Yield-Simple-Approach-or-Python | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return all(c1 == c2 for c1, c2 in zip(self.charWord(word1), self.charWord(word2)))
def charWord(self,wordList):
for segment in wordList:
for ch in segment:
yield c... | check-if-two-string-arrays-are-equivalent | Generate - Yield Simple Approach | Python | Abhi_-_- | 0 | 7 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,035 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741975/Generate-Yield-Simple-Approach-or-Python | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ''.join(word1) == ''.join(word2) | check-if-two-string-arrays-are-equivalent | Generate - Yield Simple Approach | Python | Abhi_-_- | 0 | 7 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,036 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741881/1662.-Check-If-Two-String-Arrays-are-Equivalent(easy-python-solution) | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
i,j = 0,0
s1 = ""
s2 = ""
while i < len(word1):
s1 += word1.pop(0)
while j<len(word2):
s2 += word2.pop(0)
if s1 == s2:
... | check-if-two-string-arrays-are-equivalent | 1662. Check If Two String Arrays are Equivalent(easy python solution) | Aritra_Sen2000 | 0 | 3 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,037 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741864/One-line-python-Solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return "".join(word1)=="".join(word2) | check-if-two-string-arrays-are-equivalent | One line python Solution | VijayGupta09 | 0 | 2 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,038 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741805/Python3-One-liner | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ''.join(word1) == ''.join(word2) | check-if-two-string-arrays-are-equivalent | Python3 One liner | karinadelcheva | 0 | 1 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,039 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741703/Simple-Python-Code | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
str1 = ""
str2 = ""
for i in word1:
str1 = str1+i
for i in word2:
str2 = str2+i
return str1 == str2 | check-if-two-string-arrays-are-equivalent | Simple Python Code | dnvavinash | 0 | 2 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,040 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741617/One-Line-Python-Solution | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return (''.join(word1) == ''.join(word2)) | check-if-two-string-arrays-are-equivalent | One Line Python Solution | mansoorafzal | 0 | 4 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,041 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741603/Python-(Faster-than-99.9)-or-One-liner | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return ''.join(word1) == ''.join(word2) | check-if-two-string-arrays-are-equivalent | Python (Faster than 99.9%) | One-liner | KevinJM17 | 0 | 6 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,042 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741570/My-Python-Simple-Solution-or-Beginner's-Friendly | class Solution(object):
def arrayStringsAreEqual(self, word1, word2):
a, b = '', ''
for ch in word1: a += ch
for ch in word2: b += ch
return a == b | check-if-two-string-arrays-are-equivalent | My Python Simple Solution | Beginner's Friendly | its_krish_here | 0 | 1 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,043 |
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/2741496/Python-O(n)-solution-Accepted | class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return "".join(word1) == "".join(word2) | check-if-two-string-arrays-are-equivalent | Python O(n) solution [Accepted] | lllchak | 0 | 1 | check if two string arrays are equivalent | 1,662 | 0.833 | Easy | 24,044 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871793/Python3-GREEDY-FILLING-()-Explained | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
res, k, i = ['a'] * n, k - n, n - 1
while k:
k += 1
if k/26 >= 1:
res[i], k, i = 'z', k - 26, i - 1
else:
res[i], k = chr(k + 96), 0
return ''.join(res) | smallest-string-with-a-given-numeric-value | ✔️ [Python3] GREEDY FILLING (🌸¬‿¬), Explained | artod | 56 | 2,900 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,045 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1038948/Python.-3-lines.-faster-than-100.00.-cool-and-clear-solution. | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
z = (k - n) // 25
unique = chr(k - z * 25 - n + 97) if n - z else ""
return "a"*(n-z-1) + unique + "z"*z | smallest-string-with-a-given-numeric-value | Python. 3 lines. faster than 100.00%. cool & clear solution. | m-d-f | 4 | 413 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,046 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1873379/Python-Solution | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
ans = ''
while (n - 1) * 26 >= k:
ans += 'a'
n -= 1; k -= 1
ans += chr(ord('a') + (k % 26 or 26) - 1)
ans += 'z' * (n - 1)
return ans | smallest-string-with-a-given-numeric-value | ✅ Python Solution | dhananjay79 | 3 | 69 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,047 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871949/Python3-O(n)-time-and-O(1)-space-complexity-solution | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
result =[0]*n
for position in range(n-1,-1,-1):
add = min(k -position,26)
result[position] = chr(ord("a")+add -1)
k-=add
return "".join(result) | smallest-string-with-a-given-numeric-value | [Python3] O(n) time and O(1) space complexity solution | bhushan-dhumal | 3 | 167 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,048 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/944693/Python-3-or-5-line-Greedy-O(N)-or-Explanation | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
ans = ['a'] * n
k, i = k-n, n-1
z, nz = divmod(k, 25) # `z`: number of *z* I need, `nz`: ascii of the letter just to cover the leftover
ans[n-1-z] = chr(nz + ord('a')) # adjust the left over `k` u... | smallest-string-with-a-given-numeric-value | Python 3 | 5-line Greedy O(N) | Explanation | idontknoooo | 3 | 192 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,049 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872162/Greedy-Python-Solution-with-Explanation | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
offset, arr = 96, []
for i in range(n):
j = 1
# Meaning that if we consider the current char to be 'a' then the remaining
# number of numeric value k cannot be divided into required number of 'z'
... | smallest-string-with-a-given-numeric-value | Greedy Python Solution with Explanation | anCoderr | 2 | 148 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,050 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871726/python-3-oror-O(n) | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
res = ''
for i in range(n):
q, r = divmod(k, 26)
if r == 0:
q -= 1
r = 26
if n - q - i >= 2:
res += 'a'
k -= 1
else:
... | smallest-string-with-a-given-numeric-value | python 3 || O(n) | dereky4 | 2 | 157 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,051 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872251/Easy-Python3-Solution-oror-With-Explanantion | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
dp = ["a"] * n #1
val = n #2
i = n-1 #3
while i >= 0 and val < k :
x = ... | smallest-string-with-a-given-numeric-value | 🕸️🕸️✅✅ Easy Python3 Solution || With Explanantion | Into_You | 1 | 65 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,052 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872129/Python-or-Greedy-Solution | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
# Build a list to store the characters
smallest_string_list = ["a" for _ in range(n)]
# Traverse from right to left using greedy approach
for position in range(n, 0, -1):
# Assign the slot with the max... | smallest-string-with-a-given-numeric-value | Python | Greedy Solution | aravindsb | 1 | 24 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,053 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871869/Python-3-Two-liner-O(N)-using-Math-with-Explanation-(No-Loop) | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
l = math.ceil((k - n) / 25)
return (n - l) * 'a' + chr(k - (n - l) - (l - 1) * 26 + ord('a') - 1) + (l - 1) * 'z' | smallest-string-with-a-given-numeric-value | Python 3 Two-liner O(N) using Math with Explanation (No Loop) | xil899 | 1 | 25 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,054 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1327319/Python-solution-in-O(1)-time | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
d = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}
x ... | smallest-string-with-a-given-numeric-value | Python solution in O(1) time | EklavyaJoshi | 1 | 67 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,055 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1091951/Python-greedy | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
# Edge case
k -= n
if k == 0:
return "a"*n
# idx -> char
mapping = {i+1 : c for i, c in enumerate("abcdefghijklmnopqrstuvwxyz")}
# Temp variables
res... | smallest-string-with-a-given-numeric-value | Python greedy | dev-josh | 1 | 127 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,056 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1039840/Python-%2B-explanation | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
res = [] # use list because it is faster to concatenate it
# than create new string each time adding character
# while we still got to add some characters
while n > 0:
diff = n * 26 - k
# if every character should ... | smallest-string-with-a-given-numeric-value | Python + explanation | MariaMozgunova | 1 | 82 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,057 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/944647/Python-Easy-Solution | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
k-=n
l=['a']*n
for i in range(n-1,-1,-1):
v=min(k,25)
l[i]=chr(v+97)
k-=v
return ''.join(l) | smallest-string-with-a-given-numeric-value | Python Easy Solution | lokeshsenthilkumar | 1 | 139 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,058 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/2740421/Python-O(n)-math-solution-explained | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
k -= n
t = k // 25
r = k % 25
if t < n:
ans = (n - t - 1) * 'a' + chr(r + 97) + t * 'z'
else:
ans = n * 'z'
return ans | smallest-string-with-a-given-numeric-value | [Python] O(n) math solution, explained | Valjeanzz | 0 | 2 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,059 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/2676540/Simple-Python-Solution-or-Greedy-or-TC%3A-O(n) | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
s=['a']*n
value=n
i=n-1
while value<k:
if k-value-1>=25:
value+=26-1
s[i]='z'
else:
val=k-value
# print(val)
cha... | smallest-string-with-a-given-numeric-value | Simple Python Solution | Greedy | TC: O(n) | Siddharth_singh | 0 | 1 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,060 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/2135418/Python-greedy-from-the-back | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
char = {i + 1: c for i, c in enumerate(string.ascii_lowercase)}
result = ['a'] * n
idx = n - 1
to_assign = k - n
while to_assign > 0:
value = min(25, to_assign)
result[idx] = char[valu... | smallest-string-with-a-given-numeric-value | Python, greedy from the back | blue_sky5 | 0 | 14 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,061 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1876978/Python-Solution-76-faster | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
res = n * ["a"]
k = k - n
i = n - 1
while i >= 0:
if k > 25:
k = k - 25
res[i] = 'z'
i -= 1
else:
res[i] = chr(97+k)
... | smallest-string-with-a-given-numeric-value | Python Solution 76% faster | pradeep288 | 0 | 21 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,062 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1873287/pythonor2approachorbrute-forceoroptimaloreasy-to-understand | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
ans=["a"] * n
k-=n #k=27-3=24
i=-1
while k>25:
k-=25
ans[i]="z"
i-=1
ans[i]=chr(k+97)
return "".join(ans) | smallest-string-with-a-given-numeric-value | python|2approach|brute force|optimal|easy to understand | YaBhiThikHai | 0 | 18 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,063 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1873287/pythonor2approachorbrute-forceoroptimaloreasy-to-understand | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
q,r=divmod(k-n,25)
return ("a"*(n-q-1) + chr(97+r) + "z"*q if r!=0 else "a"*(n-q)+ "z"*q) | smallest-string-with-a-given-numeric-value | python|2approach|brute force|optimal|easy to understand | YaBhiThikHai | 0 | 18 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,064 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1873203/Python-or-Simple-solution | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
i = 0
s = ""
res = 26*n - k
while i<n:
num = 26
if res - 25>=0:
num = 1
res-=25
else:
while num>1 and res>0:
num... | smallest-string-with-a-given-numeric-value | Python | Simple solution | zouhair11elhadi | 0 | 13 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,065 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1873158/Python3-simple-solution | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
solution = ["a" for k in range((n))]
k-=n
cur_char = n - 1
while k > 0:
val = min(k, 25)
solution[cur_char] = chr(ord(solution[cur_char]) + val)
k-=val
if val == 25:
... | smallest-string-with-a-given-numeric-value | Python3 simple solution | alessiogatto | 0 | 11 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,066 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872954/Python-beginner-friendly-solution | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
ref = {i+1: c for i, c in enumerate('abcdefghijklmnopqrstuvwxyz')}
res = ''
for i in range(1, n):
if self.checkRemaining(n-i, k-1):
res += ref[1]
k -= 1
else:
... | smallest-string-with-a-given-numeric-value | Python beginner-friendly solution | Mowei | 0 | 9 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,067 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872801/Python3-solution-or-Easy-to-understand!!-or-Using-while-loop | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
ans=['a']*n
k = k-n
i=n-1
while k>0:
if k<26:
ans[i] = chr(97+k)
break
else:
ans[i] = 'z'
k-=25
i-=1
return ''... | smallest-string-with-a-given-numeric-value | Python3 solution | Easy to understand!! | Using while loop | mrprashantkumar | 0 | 12 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,068 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872729/Python-O(n)-solutions | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
res = [0] * n
for i in range(n):
j = min(26, k - (n - i - 1))
k -= j
res[n-i-1] = chr(j + 96)
return ''.join(res) | smallest-string-with-a-given-numeric-value | Python O(n) solutions | atiq1589 | 0 | 13 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,069 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872108/Python-Solution-or-Greedy-or-With-Explanation-or-Easy | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
result = ""
# build from right to left
for i in range(n-1, -1, -1):
# k-i: we must leave some value from k, that is, 1 numeric value for each remaining position
# 26: the value of 'z'
... | smallest-string-with-a-given-numeric-value | Python Solution | Greedy | With Explanation | Easy | Mikey98 | 0 | 19 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,070 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872094/Python-oror-Time-O(n)-oror-Space-O(1)-oror-Explained-oror-Easy-To-understand | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
#In ans list I will store the result in reverse order.
#if result = "aaszz", then ans = ['z', 'z', 's', 'a', 'a']
ans = []
for i in range(n):
# If the value is >= 26, then max we can take 26
# 26 means 'z'
if ... | smallest-string-with-a-given-numeric-value | ✅ Python || Time = O(n) || Space = O(1) || Explained || Easy To understand | tusharkanti2001maji | 0 | 11 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,071 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872035/Easy-and-Faster-Python-Solution-Using-Greedy-Approach | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
d={1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j',
11:'k',12:'l',13:'m',14:'n',15:'o',16:'p',17:'q',18:'r',19:'s',20:'t',
21:'u',22:'v',23:'w',24:'x',25:'y',26:'z'}
result = ''
current_char = 26
while n > 0 :
wh... | smallest-string-with-a-given-numeric-value | Easy and Faster Python Solution Using Greedy Approach ✔✔👍🔥 | ASHOK_KUMAR_MEGHVANSHI | 0 | 17 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,072 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871987/Python3-or-Greedy-or-Recursive-and-Iterative-or-Easy | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
result = []
remaining = n
number = k
while remaining > 0:
if remaining == 1:
result.append(chr(number + 96))
else:
maximum_can_use = min(26, number - remaining ... | smallest-string-with-a-given-numeric-value | Python3 | Greedy | Recursive & Iterative | Easy | suhrid | 0 | 21 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,073 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871974/Python3-98.29-or-Greedy-O(N)-or-Elegant-Implementation | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
arr = [1] * n
i = len(arr) - 1
sum_ = n
while k - sum_ != 0:
if k - sum_ > 25:
arr[i] += 25
sum_ += 25
i -= 1
else:
... | smallest-string-with-a-given-numeric-value | Python3 98.29% | Greedy O(N) | Elegant Implementation | doneowth | 0 | 9 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,074 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871950/6-line-greedy-filling-in-Python | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
ans, a = ['a'] * n, ord('a')
for i in range(n - 1, -1, -1):
v = min(k - i, 26)
ans[i] = chr(a + v - 1)
k -= v
return "".join(ans) | smallest-string-with-a-given-numeric-value | 6-line greedy filling in Python | mousun224 | 0 | 14 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,075 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871926/2-line-Python-(95-46ms)-with-proof-and-explanation | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
c = min((k - n) // 25, n-1)
return 'a'*(n - c - 1) + chr(k - (n - c - 1) - 26*c - 1 + ord('a')) + 'z'*c | smallest-string-with-a-given-numeric-value | 2-line Python (95% 46ms) with proof and explanation | dwen9 | 0 | 14 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,076 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871884/Python3-Greedy-O(N)-with-comments | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
rem = k
ret = [None]*n
for i in range(n):
# greedy: push "a" if we still have enough characters for remainder
if (n-i-1)*26 >= rem-1:
ret[i] = "a"
rem -= 1
... | smallest-string-with-a-given-numeric-value | [Python3] Greedy O(N) with comments | oyqian | 0 | 15 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,077 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871851/Python-Simple-Beginner-Friendly-oror-O(n)-oror-Greedy | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
ans = [0]*n
for i in range(n-1, -1, -1):
val = min(26, k - i)
ans[i] = chr(97+val-1)
k -= val
return ''.join(ans) | smallest-string-with-a-given-numeric-value | ☑ Python Simple Beginner Friendly || O(n) || Greedy | 57Nights | 0 | 23 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,078 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871797/PHP-fast-non-iterative-mathy-solution-(still-O(n))-with-explanation-also-python3 | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
# The string will have:
# 0+ a's followed by
# 0 or 1 of a letter between a and z followed by
# 0+ z's
#
# To get the lexicographically smallest string we try to maximize t... | smallest-string-with-a-given-numeric-value | PHP fast non-iterative mathy solution (still O(n)) with explanation - also python3 | crankyinmv | 0 | 19 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,079 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871767/Python-two-solutions-one-without-arrays-an-the-other-with-arrays-70-ms-faster-than-83.87 | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
if k/26 ==n
return "z"*n
k =k-n
number_of_z,notz = divmod(k,25)
return "a"*(n-number_of_z-1) + chr(notz+ord('a')) + "z"*number_of_z | smallest-string-with-a-given-numeric-value | Python, two solutions, one without arrays an the other with arrays 70 ms, faster than 83.87% | carlosurteaga | 0 | 16 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,080 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1871767/Python-two-solutions-one-without-arrays-an-the-other-with-arrays-70-ms-faster-than-83.87 | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
# create an array equal to n, I wan n letters
arr_response = [1]*n
# remainder
k =k-n
#idx
i = n-1
# avoid calculation each time
ascci_a = ord('a')-1
# start iterating from the lasted to the first
... | smallest-string-with-a-given-numeric-value | Python, two solutions, one without arrays an the other with arrays 70 ms, faster than 83.87% | carlosurteaga | 0 | 16 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,081 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1805754/python-solution | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
if n == k:
return 'a'*k
c = 1 #c will be the number of 'z's required
while True:
if n - c + (26 * c) >= k:
break
else:
c += 1
if ... | smallest-string-with-a-given-numeric-value | python solution | MS1301 | 0 | 26 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,082 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1040024/Python-3-or-Straightforward | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
res = []
while n:
# last (n-1) char needs to be all 'z' to represent the k
if k-(n-1)*26 > 1:
val = (k-(n-1)*26)
# last (n-1) char can represent k-1, current value can be minimum
... | smallest-string-with-a-given-numeric-value | Python 3 | Straightforward | geoffrey0104 | 0 | 34 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,083 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1039851/Python3-Loop | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
if k < n:
raise Exception('Shit! Wont work!')
res = [1]*n
rest = k-n
i=n-1
while rest and i>=0:
if rest>=25:
res[i]=26
rest-=25
... | smallest-string-with-a-given-numeric-value | [Python3] Loop | charlie11 | 0 | 28 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,084 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1038763/O(n)-solution-python3 | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
i=0
r=0
res=""
if(k%26):
r=1
while( (n-i) > (k//26+r) ): #try to take as many "a" as possible.
res+="a"
i+=1
k-=1
if(k%26):
... | smallest-string-with-a-given-numeric-value | O(n) solution python3 | _Rehan12 | 0 | 22 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,085 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/947423/Simple-Python-Solution-O(n) | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
s=""
for i in range(n):
s+='a'
k-=n
l=['a']*n
i=n-1
while k>0:
y=min(k,25)
l[i]= chr(ord('a')+y)
k-=y
i-=1
... | smallest-string-with-a-given-numeric-value | Simple Python Solution- O(n) | Ayu-99 | 0 | 40 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,086 |
https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872396/Python3-Solution-with-using-greedy-approach-%2B-comments | class Solution:
def getSmallestString(self, n: int, k: int) -> str:
# set all 'a' char
res = ['a' for _ in range(n)]
k -= n
idx = n - 1
while k > 0:
k += 1 # return num value of current 'a' char
char_num_val = min(k, 26) # 26 - num value of 'z... | smallest-string-with-a-given-numeric-value | [Python3] Solution with using greedy approach + comments | maosipov11 | -1 | 8 | smallest string with a given numeric value | 1,663 | 0.668 | Medium | 24,087 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/1775588/WEEB-EXPLAINS-PYTHONC%2B%2B-DPPREFIX-SUM-SOLN | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
if len(nums) == 1:
return 1
if len(nums) == 2:
return 0
prefixEven = sum(nums[2::2])
prefixOdd = sum(nums[1::2])
result = 0
if prefixEven == prefixOdd and len(set(nums)) == 1:
result += 1
for i in range(1,len(nums)):
if i =... | ways-to-make-a-fair-array | WEEB EXPLAINS PYTHON/C++ DP/PREFIX SUM SOLN | Skywalker5423 | 6 | 264 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,088 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/2844663/DP-one-pass-O(n)-python-simple-solution | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
odd, even = 0, 0
for i in range(len(nums)):
if i % 2:
odd += nums[i]
else:
even += nums[i]
ret = 0
left_even = left_odd = 0
for i in range(len(n... | ways-to-make-a-fair-array | DP one-pass O(n) / python simple solution | Lara_Craft | 0 | 1 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,089 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/2814580/Python-(Simple-Maths) | class Solution:
def waysToMakeFair(self, nums):
ans1, ans2 = sum(nums[0::2]), sum(nums[1::2])
total = toggle = 0
for i in range(len(nums)):
if i%2 == 0:
ans1 -= nums[i]
if ans1 == ans2:
total += 1
ans2 += nums[i... | ways-to-make-a-fair-array | Python (Simple Maths) | rnotappl | 0 | 1 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,090 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/2796320/Python3-or-Prefix-and-Suffix-Sum | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
n = len(nums)
left = [[] for i in range(n)]
right = [[] for i in range(n)]
even,odd,ans= [0]*3
for i in range(n):
left[i] = [even,odd]
if i % 2 == 0:
even+=nums[i]
... | ways-to-make-a-fair-array | [Python3] | Prefix and Suffix Sum | swapnilsingh421 | 0 | 8 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,091 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/2741884/Python3-Commented-Prefix-Sum-Solution | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
# we can make an array where we save the prefix sum
# for every even and odd number
even = 0
odd = 0
# save the prefix sums
for idx, num in enumerate(nums):
# check whether we are odd or ... | ways-to-make-a-fair-array | [Python3] - Commented Prefix-Sum Solution | Lucew | 0 | 1 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,092 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/1884589/Python-easy-to-read-and-understand-or-prefix-sum | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
n = len(nums)
even, odd = [], []
evensum, oddsum = 0, 0
for i, num in enumerate(nums):
if i % 2 == 0:
evensum += num
else:
oddsum += num
even.append(... | ways-to-make-a-fair-array | Python easy to read and understand | prefix-sum | sanial2001 | 0 | 101 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,093 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/1367564/Python3-simple-solution | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
oddsum = evensum = 0
for i in range(len(nums)):
if i%2 == 0:
evensum += nums[i]
else:
oddsum += nums[i]
even = odd = count = 0
for i in range(len(nums)):
... | ways-to-make-a-fair-array | Python3 simple solution | EklavyaJoshi | 0 | 90 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,094 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/1100405/Python3-prefix-sum | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
odd, even = [0], [0]
for i, x in enumerate(nums):
if i&1: odd.append(odd[-1] + x)
else: even.append(even[-1] + x)
ans = 0
for i in range(len(nums)):
if odd[i//2] + eve... | ways-to-make-a-fair-array | [Python3] prefix sum | ye15 | 0 | 74 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,095 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/1100405/Python3-prefix-sum | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
prefix = [0]*2
suffix = [sum(nums[::2]), sum(nums[1::2])]
ans = 0
for i, x in enumerate(nums):
suffix[i%2] -= x
if prefix[0] + suffix[1] == prefix[1] + suffix[0]: ans += 1
... | ways-to-make-a-fair-array | [Python3] prefix sum | ye15 | 0 | 74 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,096 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/1080987/Python-Beats-97-speed-and-99-memory | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
s1, s2 = sum(nums[::2]), sum(nums[1::2])
ans = 0
# t1 is current odd sum, t2 — even
t1 = t2 = 0
for i in range(len(nums)):
if i & 1:
t2 += nums[i]
# If we remove ... | ways-to-make-a-fair-array | [Python] Beats 97% speed and 99% memory | UladzislauB | 0 | 137 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,097 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/970526/Intuitive-approach-with-sliding-window | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
even_sum = sum([nums[i] for i in range(0, len(nums), 2)])
odd_sum = sum([nums[i] for i in range(1, len(nums), 2)])
'''
nums = [2,1,6,4]
even_sum = 8, odd_sum = 5
front_even_sum = front_odd_sum ... | ways-to-make-a-fair-array | Intuitive approach with sliding window | puremonkey2001 | 0 | 58 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,098 |
https://leetcode.com/problems/ways-to-make-a-fair-array/discuss/953224/Simple-Python-Prefix-Solution | class Solution:
def waysToMakeFair(self, nums: List[int]) -> int:
even=[]
odd=[]
e=0
o=0
for i in range(len(nums)):
if i%2==0:
e+=nums[i]
else:
o+=nums[i]
even.... | ways-to-make-a-fair-array | Simple Python Prefix Solution | Ayu-99 | 0 | 70 | ways to make a fair array | 1,664 | 0.635 | Medium | 24,099 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.