Annaโs focus on the raw problem-solving process successfully shifts the narrative from performative expertise to authentic pedagogical transparency. It is a commendable effort to demystify the intellectual labor behind software engineering.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
LeetCode with Me: Solving Problems Blind (Mistakes Included)Added:
I'm feeling good about this because I think I've actually understood how this is working or how this should work. No, damn. If you've been here before, you know the drill. It's time for another lead code session. And if this is your first time here, I do these mostly every other week. And what we do is I take two completely random lead code questions and do them on the fly. So, you see my raw thought process and all the mistakes I make and things I try. So, without further ado, let's get into it. Random one. Oh, we've got an easy one for our first one. All right. Find center of star graph. There is an undirected star graph consisting of n nodes labeled from one to n. A star graph is a graph with a there is one center node and exactly n minus one edges that connect the center node with every other node.
You're given a 2D integer array edges.
Uh-huh, indicates there's an edge between the nodes U and V. Return the center of the given star graph. Okay.
So, we have an edge list for a representation of the graph. And what we want to do is Okay, so every single node is going to be connected only to the center.
Is that right? There's one center node and exactly n minus one edges that connect the center node with every other node. Okay, so there is exactly n minus one edges. Okay, so we only need to look at two edges, the first two. And whichever node appears in both is the center node. Am I right? That seems to be correct. Yeah, this is like insanely easy. Okay, maybe I shouldn't say that.
Might not be easy to everyone. Okay, so first two edges, find the shared node.
Let's see. One in edges zero, return this. Otherwise, return Wait, I just one zero. So, the first element of the second list is in here, return that one, otherwise return the second one. That's what it's going to have to be. Are there any edge cases where that doesn't happen? I don't think so. Let's see if it works. Oh, wait, typo.
Okay, that is correct. Let's see. Is it correct? Oh, there we go. Yep, that is the correct answer. Okay, that has got to be a record for the shortest LeetCode with me problem that we have done so far. Wow.
>> After a strong start, I see.
>> Okay, let's do another one, random. Find indices with index and value difference two. You are given a zero-indexed integer array nums having length length n and integer index difference and an integer value difference. Your task is to find two indices I and J both in the range zero and minus one that satisfy the following condition conditions. Two indices that are within the range of nums where the difference between I and J is greater than or equal to the is at least the index difference and the difference between the numbers is at least the value difference. Return integer array answer where answer is I J if there if there are two such indices and negative one negative one otherwise.
If there are multiple choices for the two indices, return any of them. So, we want them to be big and we want the difference to be big. Okay. The easiest would be if this was a sorted array, but I don't think we have such luck. Because we cannot sort it because the indices do matter. Now, what is the index difference and value difference potentially? Okay, it could be zero. I'm thinking because we need to find two indices, that is an indication this could be solved with two pointers.
Um now, the question is should we start from opposite ends or should we start together? We shouldn't start together because we should start at least at the difference of index difference. Can the index difference be greater than the length of the nums? It could be. It never says that it's not. So, let's test that edge case first. Um the difference between the index is greater than the length of the nums. Okay, so I'm minus J. So, let's see let's say we have like this. We have length is four. This difference between 0 1 2 3 - 0 is 3. So, it cannot be greater than len nums minus 1.
Okay, so that's our edge case.
Otherwise, let's have the two pointers start. So, for example, index difference two, we start at five and four. The value difference is one. We move to one and one. The value difference is zero.
So, then we go back and we increase the index difference. Okay, so I think we do need a loop. We can't completely just have a one pass.
But, we can have a loop where we start with the minimal index difference between two pointers and move them together. And then every in every loop, we increase it by one until we can no longer increase it. So, we start with index difference and we end with So, we can do 5 4 and then we can do 5 1. In this case, the maximum index difference is 3 - 0 is 3, which is len nums - 1. Okay, [snorts] so that is our outer loop of differing our index differences and then that's going to be our second pointer. And then our first pointer is going to be just from 0 to our current index difference.
Um No.
Our length of our nums minus 1 minus our current index difference. Think, right?
I love command slash. When working with different languages, I never to remember how to actually make a comment. Okay, so this is going to be our second pointer and this one is going to be our first pointer. So, our first pointer is going to start at zero and then let's say our index difference is two. So, it's going to stop it should stop at one. 4 minus 1 minus 2. So, 4 minus 3 so 1. Yeah, perfect. Okay. Then, we go if the I minus nums J and the absolute value of the difference of those is greater than or equal to nums no value difference, then we return J I. And then at the end, if we couldn't find anything, we return that. Should be 0 3.
Okay. For this one, it's 0 0. For this one, the answer is we can't. So, why for this one did it not work? So, this is 5 1 4. This was an This was the example.
We shouldn't have had that. Okay, then for I in range 2 to 3. Hmm, I think it's the range. It's the fact that the range actually ends one before that. So, let's actually get rid of negative to minus get rid of minus one. There we go.
Ranges always trip me up every single time.
All right, that is incorrect. So, what did I do? I did 1 2 with an index difference is one. It should be two.
Hmm, so what happened here? How did we end up looking at something that is not a big enough index difference because that shouldn't happen. So, for I in range 2 to 5. So, 2 3 and 4. So, that means the second pointer could be 2 3 or 4. And then, the first pointer can be I don't think we're actually doing this right. So, this is going to be the index difference, not pointer two. This is difference. This is pointer one, pointer one, pointer two. Pointer one, pointer two. Yeah, our indexing was completely wrong. Uh-huh. Oh, yes. Yeah, diff.
There we go. Okay.
All right, time limit exceeded. So, does that mean that we did not use the correct approach? So, what I'm noticing is that these are all five-digit numbers, and this value difference is huge. So, maybe we could have an edge case catcher where we say that if Okay, I wonder if this is going to impact the performance greatly, but if we say if the max of nums minus the min of nums is less than value difference, then we also can never find anything, right? [clears throat] So, let's see if that actually helps anything, because in this case it will catch it, I think. But in other cases, it might just slow it down. K. So, again, what How can we improve this?
Look at Look at the topics. Okay, array two pointers. Okay, so we do have a correct approach, or we did pick the right pattern to use. Let's take a look.
Okay, for each diff Okay, so for each thing that we have that we call that we're calling diff at this point, keep indices J1 in the range 0 I minus index difference such that nums J1 and nums J2 the minimum and maximum values in the index range. Wait, so this is more of a sliding window thing.
Okay.
So, clearly, we can't do O of n squared nested for loops. So, what can we do instead? How can we get the same result with less information? Uh, no. I did not know that was a shortcut. Okay. I guess command return does a submit. Did not know that. Okay, so I think this is still a good for loop to have. So we go from A range index difference. So for example, here two from two to here. And then what do we need to have just that? I think what if we had like the a sort of like a sliding window approach in which when we start here, it's the difference between five and four. We could store something like the minimum and the maximum because the difference is between the minimum and the maximum element is going to be our biggest value difference and we want the value difference to be bigger than something. But we also want to keep track of the indices. So maybe we could keep track of the indices of the smallest and largest values. So in other words, for example, when we start here, so we have a min index and we have a max index, right? So our min index is going to be one and then our max index here currently is going to be zero, right? And then we move Okay, yes, yes, yes. So we we start with kind of a sliding window of that and then we keep adding Sorry, we start with and then we keep adding one more and one more and one more. So like if we pretend there's this was longer.
So we start like this because that is our minimum index difference is two. So between five and four. Our current minimum index is one and our max index is zero. That it does not have a difference of one, so we expand. We have another index now of like instead of one, it's now at two three and between five and one it's bigger than value difference and that's our answer. Would that actually work? I think that would actually work. Yeah, and then if we don't, we continue expanding and expanding until we find the differences that have the appropriate index difference and the appropriate value difference. Okay, so first we want it to create the first window, right? Which is create initial indices where um well, at first they're going to be the min and the max are both going to be just at zero when we first and then we will um go from zero to the index difference, right? So the first one to be this big, so we go from zero to one, two. The index difference is two, so we actually want to go index difference plus one, I think.
Although no, we want to start here, right? So we'll just go We'll just say in we'll go to index difference um and then we go if nums I is greater than nums max I, max I is I and then same thing for mini or min I is less than or equal to actually. Yes, that was a key thing that we did discover is that we wanted to be less than or equal to. Although that might be good in some cases and then not good in other cases. But we'll just try it this way and then if it doesn't work we can return to this part. So indices. Okay, now we're able to start here, right? So we have that and then we start at zero, one Wait, no.
So we've gone through these two. Okay, let let's trace this for a second. So for I in range zero, okay, so zero. Zero is less than or equal to zero, zero equals zero. Okay, we can actually start at one, I think. Yeah, cuz that zero is just redundant. Okay, so range So one is nums one is greater than nums nums max I, it's not. Okay, so max I is still zero and then if max I is zero and then min I if nums I is less than five, it is now max I is at one. And then we've I've gone from one to two.
That is where we stop. Okay. So for diff in range, okay, so now we go the difference. We'll just rename that I as well, why not? Okay. So for I in range, okay, now we start from here and then we go to the end checking the min knee and the maxie same as before except now we also check if the difference between the indices is appropriate and the difference between the values is appropriate, we return. So and I minus nums min I is greater than absolute value difference, then we return well say I max I cuz it says it doesn't matter which order. Okay, let's see if that works. First off, we got our test results. Okay, so that does work in our test cases. Let's see if it works in our submission. Wrong answer. Well, that's better than time limit exceeded, so we can work with that.
See, wrong answer means we have maybe a typo or a logic error somewhere. Whereas time limit is exceeded usually means we use the entirely wrong approach and we kind of have to start from scratch.
So I much prefer seeing wrong answer. So we are saying we don't have an answer when we actually do. So what's happening here?
Let's do a dry run for this test case.
So we start with 0 0. We start with in range 1 2. So for just this one, is it greater than? No, it's not greater than that. It's not greater than two. Is 0 less than or equal to two? Yes. So, we now update this one. Actually, it would be easier if we do it in the same order.
Yes, so we update that one. And then we go to we now go to our index difference. So, index difference is four. Okay, so we start with two. So, is nine greater than two? Yes. So, we change that. Is nine less than zero? It is not. Aha, so we actually don't need the max and the min. Yeah, because it could be between two and nine and it would have been fine. But we are updating it to only have the min max min and the max. Okay, so our problem is that we're comparing the minimum and the maximum and that is not the correct approach at all. However, a different way we can think about this is that we actually go through every single one and um it's biggest uh value difference between before it's big Oh, yes, yes.
Okay, this is all clicking into place now.
For every value or for every num that we check, it's biggest value difference is going to be either with the previous maximum or the previous minimum. And we can go ahead and only check at least value difference before it for the minimum and maximum to ensure it satisfies the index difference. So, what we actually want to do is we want to have something like we start at nine because that is Let's say every here. And then index difference is two, so we start at two because it has to because nine is the first second index that we can have or to to put it less confusingly, nine is the first right index that we can have and then because then two will be left index. Now, when we look back to because that is the maximum index, what is the maximum and what is the minimum we can have? The maximum is at zero and the minimum is at zero. The maximum is two and the minimum is two. So, that is So, the biggest difference between nine and something before it is going to be either two or two. If that is a big enough difference according to value difference, then we can return that.
Okay. So, let me just start from scratch. Start with index difference.
Okay, so that's our I. Okay, and then max and min and zero. Okay. So, if nums I minus nums max I, okay, so maximum, let's say absolute value of those two and then we will also check min I. So, if the absolute value absolute difference so that if the difference between those two is greater than value difference, except it's not at I, it's at I minus index difference.
No. No, no, no, no, it's not. So, if it's nine is less is less than Okay, the difference between nine and two is greater than or equal to value difference or difference between two and not nine and two is a different is greater than equal to value difference, then we return I max I or return I min I. And then we want to update the kind of like prefix something for the next iteration by saying if I is greater than or equal to or it doesn't have to be equal to. Actually, we'll say if I is greater than max I, then No. If nums at So, if nums at I is greater than nums at max I, then max I is going to now be I. And then we do the same thing for min. Min.
Now, don't think it matters too much here whether it's greater than or equal to or just greater than. Let's see if that works.
Okay, and then let's just use this test case real quick. Okay, so that test case does work. Okay. All right. I'm feeling good about this because I think I've actually understood how this is working or how this should work. No.
[clears throat] Damn. Okay, so 4 3 is not a good difference. Shoot. How does We are never using index difference here.
Hold on. So, we are now adding nine, but we never added zero. So, before we do that, we actually should add minus index difference plus one. I think it's I minus index and plus I think that's what we need to add. And then let's add this test case as well. Yeah, yeah. I'm not paying for it, no matter how much you want me to.
Okay, so that still doesn't work cuz still it gives us 4 3.
Why is it giving us 4 3? Oh, oh, oh, we did we never updated this. We never updated this. There we go. Okay. Okay, feeling confident now. Okay, there we go. It's accepted. It's accepted. Now, we did have memory eh, it's okay. It's one of those things that could be difference of just resubmitting and then it'll do it. Here on the other hand, hmm.
Some are getting like almost half my run time, but let me just see if it is also a fluke. Okay. So, still 51 Yeah, so that's not a fluke. Hmm.
Okay, so it's clearly there's something about memory that we're doing that's not great. Okay. So, or not memory. Memory's fine, runtime. I think it's the fact that we're doing this, and especially with big arrays, this is not going to be great. So, I I think we should just keep this edge case. Cuz that one, the second one that we just deleted was more of an optimization that we tried to do. So, let's let's see. So, that's already not happening. How did How did we not get this? So, index difference is zero, value difference is one.
Index difference is greater than the length of nums minus one. Index difference is be zero, zero. Or Okay, we can't have this because there has to be a value difference.
Or the length is Um what's the shortest length we can have according to the So, it has to be at least one. So, if it's one if it is one and value difference is not equal to zero, it's not going to work. Okay, this again doesn't work, and why does it not work? Because we have a value difference. Okay. So, we go list index difference. So, nums I So, let's say because index difference So, zero.
If zero minus zero plus one, that's one.
If one minus zero plus one, so that's two. No can do.
So, do we just not do that for the last one? See, if is less than the length of nums, I think that will fix it.
I always hate wrestling with arrays and making the indices do what I actually want.
Still out of range. Does it have to be plus one?
There's probably a more intelligent way.
Oh, there we go. Okay.
Um that is worse runtime. Hmm.
That is worse runtime.
>> Why is it worse runtime? Why?
>> Let's see. Okay, so they are also storing the number as well as the ID or index. They're also not taking the edge case. So, what happens if we don't take the edge case?
It still works. Okay, so I think in our new approach, we know it auto catches the edge case. But now I was saying there's there's there's a more intelligent way to solve leetcode problems than just changing random things about the about the indices and hoping it works. Okay, it's not completely random, but at this point, I mean, we have an accepted solution. And at this point, it's a matter of trying to figure out like what's the better more optimal approach to this. Let me take a look at like some of the post solutions. Okay, so they're doing this whole part um beforehand.
So, I did notice that this is slowed us down quite significantly, and the way they get around it here but is by doing this actually beforehands because here we have a plus one and a plus one. But if we do it at the beginning before the actual run, we can actually just use the plain I value, and it will automatically already have caught that it's not too long because we're we're it's like we're pre-doing the thing for the next round, but then we don't want to do it if there is no next round. So, if we just do it at the beginning of this round, then that does it for us automatically.
Yeah, so let's see if that helps our runtime.
Okay, that did help pretty pretty good.
I mean, went from 51 to 47, but we did that one extra if was taking up quite a bit. Let me see if we can get it down even more.
No, okay. So, how are we getting 30 seconds? Is it simply the lookups that are taking so long? The lookups shouldn't take that long.
How about the fact that they're not using any absolutes? We're using absolutes. So, let's think about this.
If it really I think what we can do is instead of doing the absolute, we can just figure out which way to not make this negative. Okay, so if the number is bigger than the maximum, then the the biggest difference isn't going to be between it and the maximum. However, if it's smaller than the maximum, then it might be useful and this will be not negative.
And same idea here. If the minimum is useful to us, then this will be bigger than the minimum, right? Yes. Okay. All right, there you go. That shaved down even even more. Okay, well, I'm pretty happy with that with that result. All right, well, that is a wrap for today's LeetCode session. As always, let me know how you would have solved these down in the comments. And if you're new here, I'm a computer science student sharing my journey to becoming a software engineer here on this channel. I do these LeetCode with me sessions every other week, and then otherwise, I'm just sharing what I'm working on, cool projects, things like that. So, if that sounds interesting, feel free to subscribe and stick around.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 viewsโข2026-05-28
How agent o11y differs from traditional o11y โ Phil Hetzel, Braintrust
aiDotEngineer
450 viewsโข2026-05-28
Re: ๐ฃ๏ธ๐theprophedu๐2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 viewsโข2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation๐ฏโ
LearnwithSahera
1K viewsโข2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 viewsโข2026-05-29
Search Algorithms Explained in 60 Seconds! ๐ค๐จ
samarthtuliofficial
218 viewsโข2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 viewsโข2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 viewsโข2026-05-29











