Excel Sheet Column Title - Leetcode 168 - Python

  Рет қаралды 14,692

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 29
@nishantsrinivas2936
@nishantsrinivas2936 Жыл бұрын
Kinda happy to know I wasn't the only one who faced mild difficulty while solving an easy problem! 😅 I came up with a recursive solution but core idea is same.
@kgCode658
@kgCode658 Жыл бұрын
I solved the same way but didn't subtract -1for column number,though i thought about it😢
@alexisxander817
@alexisxander817 Жыл бұрын
how on earth is this question tagged easy?
@shakhzod_shermatov
@shakhzod_shermatov 7 күн бұрын
Thank you for great contents as always! The following solution might be more readable for some people: class Solution: def convertToTitle(self, columnNumber: int) -> str: res = ' ' while columnNumber > 0: columnNumber -= 1 #Adjust for 1-based indexing remainder = columnNumber % 26 res = chr(65 + remainder) + res columnNumber = columnNumber // 26 #move to next digit return res
@ExecutionMods
@ExecutionMods Жыл бұрын
Starting a new leetcode subtopic is like opening up a can of worms. But I guess companies want you to know this for some reason.
@ShivangiSingh-wc3gk
@ShivangiSingh-wc3gk 15 күн бұрын
I found this more intuitive ``` class Solution: def convertToTitle(self, columnNumber: int) -> str: results = "" while columnNumber > 0: mod = columnNumber % 26 mod = 26 if mod == 0 else mod columnNumber -= mod columnNumber //= 26 results = chr( ord('A') - 1 + mod) + results return results ```
@nikhilgodase9455
@nikhilgodase9455 Жыл бұрын
wasn't able to come up with the mathematical solution for this Thanks NeetCode, also please upload video daily
@steeve1
@steeve1 Жыл бұрын
Recursive solution: ``` import string def int_to_alpha(n: int) -> str: i, j = divmod(n, 26) if i: return int_to_alpha(i - 1) + string.ascii_uppercase[j] else: return string.ascii_uppercase[j] return int_to_alpha(columnNumber - 1) ```
@yixiao8341
@yixiao8341 11 ай бұрын
very good video, i thought i wont understand this until i watched your video
@aadil4236
@aadil4236 Жыл бұрын
That third example was so weird. I multiplied 26*26 straight away and I just couldn't get it. Thanks for the explanation.
@alexandersebastiangomezdel9985
@alexandersebastiangomezdel9985 3 ай бұрын
I almost reached the solution, but at the same time, I almost gave up. There's a kind of pressure because of being tagged easy.
@uptwist2260
@uptwist2260 Жыл бұрын
Thanks for the daily
@ngneerin
@ngneerin Жыл бұрын
Was waiting for something I could understand
@RagingAcid
@RagingAcid Жыл бұрын
This is one of the rare problems I stumbled upon the solution super quickly. I always love seeing how you work things out though
@dumbfailurekms
@dumbfailurekms Жыл бұрын
u are heroic legend
@acridpie4492
@acridpie4492 3 ай бұрын
My leetcode's first question was this. And guess what i couldnt solve it and gave up
@sanchitmishra1895
@sanchitmishra1895 Жыл бұрын
@NeetCodeIO can you tell if there is inplace solution for lastIdx 2161? maybe some variation of dutch flag algo?
@nicolasguillenc
@nicolasguillenc 9 ай бұрын
I don't know how to feel atbout the fact that this one is supposed to be "easy" haha
@metarus208
@metarus208 Жыл бұрын
thanks for this
@hieijaganshi7088
@hieijaganshi7088 8 ай бұрын
Ngl it's pretty unclear as to how you come up with subtracting 1, I've spent several hours on this question and still can't derive that thought process from scratch
@VaibhavPandey-if5ux
@VaibhavPandey-if5ux 7 ай бұрын
Same, I have been racking my brain but not able to understand that part
@VaibhavPandey-if5ux
@VaibhavPandey-if5ux 7 ай бұрын
Just realised what -1 is doing. The system goes from 1-26. Subtracting 1 makes it 0-25, which is how all our calculations expect them to be.
@nathanmorlonski1265
@nathanmorlonski1265 26 күн бұрын
@@VaibhavPandey-if5ux thanks brother, you are legend
@dk4882
@dk4882 Жыл бұрын
It is really an easy one . Sir please add all these daily problems Subsequently in the NeetCode All List 🙏
@n.a3642
@n.a3642 6 ай бұрын
lmaooooooooooo easy my ass
@Jia-Tan
@Jia-Tan 2 ай бұрын
shut up, I have 1000+ LC and I don't post trash gatekeeper comments like this. Stop trying to make people feel stupid
@火災のアイスクリーム
@火災のアイスクリーム Ай бұрын
how is this easy?
@krateskim4169
@krateskim4169 Жыл бұрын
Awesome Awesome
@chibata_one730
@chibata_one730 9 ай бұрын
Changed the code a little. maybe using a map is easier to understand. func ConvertToTitle(columnNumber int) string { pairs := make(map[int]rune) s := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i, r := range s { pairs[i+1] = r } pairs[0] = 'Z' // base case if columnNumber 0 { fmt.Println("cn: ", columnNumber) mod := columnNumber % 26 res = append([]rune{pairs[mod]}, res...) // 这里必须是(columnNumber - 1) / 26 // 而不是 columnNumber / 2 , 这样会导致重复计算26的倍数。 比如702 = 26 * 26 + 26,前面已经计算了mod=0,所以要减少一个26的倍数 columnNumber = (columnNumber - 1) / 26 } fmt.Println(string(res)) return string(res) }
Find the Difference - Leetcode 389 - Python
11:24
NeetCodeIO
Рет қаралды 11 М.
Defuse the Bomb - Leetcode 1652 - Python
13:57
NeetCodeIO
Рет қаралды 6 М.
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 4,5 МЛН
Мама у нас строгая
00:20
VAVAN
Рет қаралды 8 МЛН
Happy birthday to you by Secret Vlog
00:12
Secret Vlog
Рет қаралды 6 МЛН
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 3,9 МЛН
Excel Sheet Column Title | LeetCode 168 | C++, Python
14:37
Knowledge Center
Рет қаралды 32 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 145 М.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 211 М.
How I Approach a New Leetcode Problem (live problem solving)
25:31
Diameter of Binary Tree - Leetcode 543 - Trees (Python)
11:16
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 232 М.
Excel Sheet Column Number | Leetcode 171 | Day-22 | String
8:19
Ayushi Sharma
Рет қаралды 16 М.
Add Binary - Leetcode 67 - Bit Manipulation (Python)
8:20
Greg Hogg
Рет қаралды 6 М.
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 851 М.
The LeetCode Fallacy
6:08
NeetCode
Рет қаралды 572 М.
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 4,5 МЛН