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 Жыл бұрын
I solved the same way but didn't subtract -1for column number,though i thought about it😢
@alexisxander817 Жыл бұрын
how on earth is this question tagged easy?
@shakhzod_shermatov7 күн бұрын
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 Жыл бұрын
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-wc3gk15 күн бұрын
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 Жыл бұрын
wasn't able to come up with the mathematical solution for this Thanks NeetCode, also please upload video daily
very good video, i thought i wont understand this until i watched your video
@aadil4236 Жыл бұрын
That third example was so weird. I multiplied 26*26 straight away and I just couldn't get it. Thanks for the explanation.
@alexandersebastiangomezdel99853 ай бұрын
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 Жыл бұрын
Thanks for the daily
@ngneerin Жыл бұрын
Was waiting for something I could understand
@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 Жыл бұрын
u are heroic legend
@acridpie44923 ай бұрын
My leetcode's first question was this. And guess what i couldnt solve it and gave up
@sanchitmishra1895 Жыл бұрын
@NeetCodeIO can you tell if there is inplace solution for lastIdx 2161? maybe some variation of dutch flag algo?
@nicolasguillenc9 ай бұрын
I don't know how to feel atbout the fact that this one is supposed to be "easy" haha
@metarus208 Жыл бұрын
thanks for this
@hieijaganshi70888 ай бұрын
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-if5ux7 ай бұрын
Same, I have been racking my brain but not able to understand that part
@VaibhavPandey-if5ux7 ай бұрын
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.
@nathanmorlonski126526 күн бұрын
@@VaibhavPandey-if5ux thanks brother, you are legend
@dk4882 Жыл бұрын
It is really an easy one . Sir please add all these daily problems Subsequently in the NeetCode All List 🙏
@n.a36426 ай бұрын
lmaooooooooooo easy my ass
@Jia-Tan2 ай бұрын
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 Жыл бұрын
Awesome Awesome
@chibata_one7309 ай бұрын
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) }