Daily (186 day streak)
I'll be honest, segment tree is pretty advanced stuff. I propose instead of this hard - try out simpler problem for segment tree (I also don't know the solution for it)
https://leetcode.com/problems/longest-balanced-subarray-ii/description/?envType=daily-question&envId=2026-02-11
#daily #hard
I'll be honest, segment tree is pretty advanced stuff. I propose instead of this hard - try out simpler problem for segment tree (I also don't know the solution for it)
https://leetcode.com/problems/longest-balanced-subarray-ii/description/?envType=daily-question&envId=2026-02-11
#daily #hard
π5
Today or tomorrow will post about Segment tree: how to understand it with visualisation. Note: I know one engineer who asked it once on the interview.
π₯12
andreyka26_se
Today or tomorrow will post about Segment tree: how to understand it with visualisation. Note: I know one engineer who asked it once on the interview.
As promised. Segment tree. I have heard some problems were asked about segment tree: one I mentioned already, it was asked by my former colleague at MS, second one I guess was asked at databricks, so it is good to at least have some understanding.
Segment tree is special case of binary tree that stores "ranges" or "aggregated" values, such as sum, min, max. It is needed to answer range queries for mutated source with log(n) complexity
In our sample leetcode problem, ideally simple to learn segment tree we are going to do SUM SEGMENT TREE: https://leetcode.com/problems/range-sum-query-mutable/description/
If the array is not mutated (cannot change element by index) - then it is easy preffix sum problem.
BUT, if you can change the element under index to make prefix sum work you would need to either rebuild prefix sum O(n) or calculate range sum on the fly O(n)
Segment tree on the other hand allows you to do mutation and querying in O(log n)
Segment tree is special case of binary tree that stores "ranges" or "aggregated" values, such as sum, min, max. It is needed to answer range queries for mutated source with log(n) complexity
In our sample leetcode problem, ideally simple to learn segment tree we are going to do SUM SEGMENT TREE: https://leetcode.com/problems/range-sum-query-mutable/description/
If the array is not mutated (cannot change element by index) - then it is easy preffix sum problem.
BUT, if you can change the element under index to make prefix sum work you would need to either rebuild prefix sum O(n) or calculate range sum on the fly O(n)
Segment tree on the other hand allows you to do mutation and querying in O(log n)
π4β€2π₯1
Every single node in segment tree is storing sum of some range/interval (left ... right).
Root in that case stores sum of whole array.
Left child handles left part of a whole array
Right child handles right part of a whole array
Important thing to remember that left node handles n/2 + 1 and right node handles n/2, in case of odd number of elements. If the number of elements is even - both handle equal part of the subrange.
Building the tree.
Pretty easy, resemble BST
Querying.
This part is the most confusing for me. I left the visual representation that shows where queried range (interval{left/right}) is VS where the node's range. It is not so complicated.
If queried range is completely OUTSIDE of what node handles -> skip
If queried range is fully INSIDE of what node handles -> just return node's sum, this sum is partial response that will be merged later
If queried range is intersecting at some point - then we aggregate in children and merge the response
Root in that case stores sum of whole array.
Left child handles left part of a whole array
Right child handles right part of a whole array
Important thing to remember that left node handles n/2 + 1 and right node handles n/2, in case of odd number of elements. If the number of elements is even - both handle equal part of the subrange.
Building the tree.
Pretty easy, resemble BST
Querying.
This part is the most confusing for me. I left the visual representation that shows where queried range (interval{left/right}) is VS where the node's range. It is not so complicated.
If queried range is completely OUTSIDE of what node handles -> skip
If queried range is fully INSIDE of what node handles -> just return node's sum, this sum is partial response that will be merged later
If queried range is intersecting at some point - then we aggregate in children and merge the response
π₯6π2β€1
For leetcode nerds like me. Daily is easy - just bruteforce it, go and collect the coin. I will post later evening, as donβt have access to telegram from laptop
π₯5
Daily (187 day streak)
Don't waste your time probably for finding optimal solution, it is O(n^2), however in my opinion therefore it should be easy, not mid
https://leetcode.com/problems/longest-balanced-substring-i/description/?envType=daily-question&envId=2026-02-12
#daily #medium
Don't waste your time probably for finding optimal solution, it is O(n^2), however in my opinion therefore it should be easy, not mid
https://leetcode.com/problems/longest-balanced-substring-i/description/?envType=daily-question&envId=2026-02-12
#daily #medium
π3
Daily (188 day streak)
IMO, it should be hard, as extremely hard to get with intuition. I wasn't able to solve and was hard to understand the solution tbh
https://leetcode.com/problems/longest-balanced-substring-ii/description/?envType=daily-question&envId=2026-02-13
#daily #medium
IMO, it should be hard, as extremely hard to get with intuition. I wasn't able to solve and was hard to understand the solution tbh
https://leetcode.com/problems/longest-balanced-substring-ii/description/?envType=daily-question&envId=2026-02-13
#daily #medium
π4
andreyka26_se
Promised - done: https://andreyka26.com/ticketmaster-system-design-with-microsoft-engineer #systemdesign
Next days I will drop video about this system design, with drawing and explanations
π₯13β€1
Daily (189 day streak)
Amazing problem. In general it is much more enjoyable to solve some "real world" modeled problems. However took me a bit to come up with an idea.
https://leetcode.com/problems/champagne-tower/description/?envType=daily-question&envId=2026-02-14
#daily #medium
Amazing problem. In general it is much more enjoyable to solve some "real world" modeled problems. However took me a bit to come up with an idea.
https://leetcode.com/problems/champagne-tower/description/?envType=daily-question&envId=2026-02-14
#daily #medium
π6
Daily (190 day streak)
Solid and good problem. Go to comment section I will explain how "carry" works for binary summing.
https://leetcode.com/problems/add-binary/?envType=daily-question&envId=2026-02-15
#daily #easy
Solid and good problem. Go to comment section I will explain how "carry" works for binary summing.
https://leetcode.com/problems/add-binary/?envType=daily-question&envId=2026-02-15
#daily #easy
π5
So one guy shared "easy" problem to solve, asking, why it does not feel so easy reminding me famous (in sc2) "is it imba or do I suck".
Let's do it
Let's do it
π₯4
andreyka26_se
So one guy shared "easy" problem to solve, asking, why it does not feel so easy reminding me famous (in sc2) "is it imba or do I suck". Let's do it
So, the problem, labeled as easy.
We need to make string, containing only "a" or "b" empty, by removing palindromes only.
Problem is not about coding or using some algo, more like brain puzzle, and hoping "Eureka effect" hits you before you go to hint.
https://leetcode.com/problems/remove-palindromic-subsequences/description/
We need to make string, containing only "a" or "b" empty, by removing palindromes only.
Problem is not about coding or using some algo, more like brain puzzle, and hoping "Eureka effect" hits you before you go to hint.
https://leetcode.com/problems/remove-palindromic-subsequences/description/
β€5
Daily (191 day streak)
Easy problem again, not bad one, but you will need some hint (check the comment) to not waste 10 minutes as I did.
https://leetcode.com/problems/reverse-bits/description/?envType=daily-question&envId=2026-02-16
#daily #easy
Easy problem again, not bad one, but you will need some hint (check the comment) to not waste 10 minutes as I did.
https://leetcode.com/problems/reverse-bits/description/?envType=daily-question&envId=2026-02-16
#daily #easy
π4
andreyka26_se
Next days I will drop video about this system design, with drawing and explanations
YouTube
TICKETMASTER SYSTEM DESIGN with MS Engineer
Article: https://andreyka26.com/ticketmaster-system-design-with-microsoft-engineer
Telegram: https://t.me/programming_space
Instagram: https://www.instagram.com/andreyka26_se/
X: https://x.com/andreyka26_
Tiktok: https://www.tiktok.com/@andreyka26__
Heyβ¦
Telegram: https://t.me/programming_space
Instagram: https://www.instagram.com/andreyka26_se/
X: https://x.com/andreyka26_
Tiktok: https://www.tiktok.com/@andreyka26__
Heyβ¦
π₯9