LC POTD 20/10/26 : Yeh hota hai question! Simple to understand, little difficult to implement. But no special data structure, no special logic(only cyclic check), simple array implementation
Didnt do POTD today because it's too late and it will take too long to figure it out as well.
So here's a small backtracking question for today (had not yet solved this for some reason... maybe did it on some friend's account before)
Didnt do POTD today because it's too late and it will take too long to figure it out as well.
So here's a small backtracking question for today (had not yet solved this for some reason... maybe did it on some friend's account before)
for all subarrays starting after that occurrence. Lazy propagation helps us update the entire range without visiting every element individually. The rest is just calculating the sum of squares using the formula (d+1)Β² = dΒ² + 2d + 1 and adding it to our answer for every index.
LC POTD 17/10/26: Took me more than 2 hrs. I think this is the first time I have solved a segment tree question. Had to look through solutions, videos and gpt.
P.S.: Gave some kind of explanation in replies (gonna sound like gpt thoughπ )
Essentially, we maintain a segment tree where each node stores the sum of distinct counts and the sum of their squares for a range. Whenever we encounter an element, we use a map to find its previous occurrence and increment the distinct counts (contd)...
LC POTD 17/10/26: Took me more than 2 hrs. I think this is the first time I have solved a segment tree question. Had to look through solutions, videos and gpt.
P.S.: Gave some kind of explanation in replies (gonna sound like gpt thoughπ )
Didnt think I would post about cricket again, but Shai Hope is not an upcoming player anymore, he's brought his best form and brings out the best from his team as well. So happy to see WI able to compete again, that too in India