All right, before we jump into our first classroom discussion question, it's a little bit of that increase in difficulty. Maybe seeing something a little new on the last two, at least, you haven't quite done a lot of. Yeah, a little bit, and a little bit intentionally. Probably could have happened before this point in time. But sometimes I like to use classroom discussions to really stretch kids' knowledge because they get so used to learning with cs awesome and they're at the book and this, that, and the other. And then these can become a little more mundane, so we'll see how you like it. There are various ways that you could scaffold giving kids a little bit of an introduction to the project problem, to the code talking about it a little bit as I'm about to do now. That would ratchet down difficulty, if that's what you would lie. So the first question asks what dos this code do? And the answer is it replaces with 0, because that's what's inside the if statement, right? We're changing nums sub i to 0 sometimes. It replaces with 0. Is it all negative numbers? All negative numbers that follow positive numbers? Or all negative numbers that precede positive numbers? And this brings up a really important thing that we're going to see over and over in some of these questions. And that is, let me give you our sample array down there. But we're going to be using two different indexes into num in this if statement. Meaning that we're actually accessing two parts of the array in the same iteration. On the left, we have num sub i less than 0. And on the right, we have num sub i plus 1 greater than 0. So num sub i is to the left, well, let's figure out first what each of these mean. If it's less than 0, that means it's negative. If it's greater than 0, that means it's positive. Now, we just need to figure out what the i and the i plus 1 are referring to. And there you go, the i and i plus 1. And what it is, is of course, at least the first iteration will be 0 and 1, okay? So basically, what we're saying, if the thing on the left The thing that comes before it is negative and the thing that comes after it is positive, then we're going to change. So if the item on the left is negative, and the item on the right is positive, then we change the negative number to be 0. And so, that's why all negative numbers that precede, that are on the left, of a positive number, get replaced with 0. So 10, that would get replaced with 0. And now, we've got 5 and 13. Is 5 negative? Nope, so we won't even check the other one, but, yeah. Negative 13 isn't positive either. And then, how about this last one, is negative 13 negative? Yeah, yeah, okay. Is negative 21 positive? No, so we don't do anything. This code would have changed only one thing. Might also be careful in looking at the array or the Boolean expression that causes the loop to stop. Because we're adding nums of i plus 1, that needs to be nums dot length minus 1. Second problem. What is in the array after the code runs? To be honest, if you just go straight and trace this out, it's not super tricky. I had one a little bit trickier and then I made it a little bit easier. But what I usually count on is students going I can see it's taking the thing that's on the left and putting it on the right. And they're like okay, it's moving everything to the right. And then, they think that it's, let's see, they think that it's A because they're just sort of moving every element of the array from the thing that's on the left goes into the right. because it's num sub i goes into i plus 1. But if you trace dedicatedly, you will actually don't to trace that long, you'll see very clearly a problem. We've seen it before, in fact way back with strings, we saw the same thing where we just kind of kept replicating one character. In this case, we're going to keep replicating the first value in the array. So here's our array that we've got. What's happening is in the first iteration, again, it's in index 0, num subm 0 is going to be put into numb sub 1, all right? I just did that, okay? Now, num sub 0 is 90, and num sub 1 is 90, okay? Well, it could still be A. Next one, though, numb sub 1 goes into num sub 2. We just carried num sub 1, which is 90, over to num sub 2. And the pattern shows itself. Did I do one more? I did, okay, good. Basically because we're looping up, we're just kind of taking that 90, we're overwriting all the things. We're not giving the chance for everything to move down. I did all of them. Here's how you fix it. If you want to get A, which is sort of everything moved to the right one, except we've still got that first value there, you need to loop backwards, okay? We need to start from index 3 and 4, take what's in index 3, put it in 4. So that would put 60 into where 50 is. Then, we could go down to index 2 and put that into 3. And so, we're not overwriting the values that we still need to move them up before we've moved them up. Third question, and this had something maybe could have even been completely new to students. Creating a new array and taking items from the old array and moving them into the new array, not changing them around or counting them or things like that. I like to sometimes introduce a new concept right after getting kids to try to solve a problem. They're like this is another one her regular problems blah, blah, blah, blah, blah. And it's like wait, what is going on? And usually, the level of discussion goes really high because people like she's tricking us blah, blah, blah. So there's this research on our brains that says we are far more motivated to try to figure something out after we've just been tested on it. It's getting something new. So if, in fact, your students at this point for them creating a new result array and then moving some items over is new, that will probably have pushed their brains and probably also woke them up. So let's walk through what this code is doing. So again, we've got our nums array, we've got our toRemove item, and we're creating a new array of the same length as nums, okay? because we're going to pull over all the things that aren't 3, or actually, we're going to find out where we're going to pad the rest with 0. Interesting discussion there. Don't really know what j is. Kind of a mystery. It is a ,j though, so probably thinking index into an array? We'll see. I'm looping over all of nums, as usual. And the if statement inside, for every element in nums, if it's not to be removed, then missing code. And that should be copy it into the result array. Question? Where into the results array? That is, in fact, what we want to use j for. So i is the iterator that's walking over the nums array, and it's going up 0, 1, 2, 3, 4. j, it's not going to go up every time through the loop. It's only going to increase after we copy an item into the result array. So essentially, j is keeping track of what is the next place that we should put something into a result. It started off at 0, so the very first time you copy something in, num sub i goes into result sub 0. And then, we want to increase j plus plus so that next time the if statement is true, not necessarily next time through the loop, but the next time the if statement is true, then we'll be ready to put it into result sub 1. So i is going to increase linearly and religiously without fail. j is going to increase only the times that the if statement is true, because that meant we copied another thing in. So j is keeping track of the next place we should put an item into result. And interestingly, because I kind of grabbed this to off of a coding question, so there is a coding question I will have to tell you later what it's called, similar to this. I made it a little bit easier. But the this loop here, you say what the heck is this doing? And I kind of like this because students who are working ahead, they could be like what the heck is that, and do we even need to look at it? And answer is you don't, really. This is doing a loop starting at the index j. We're reusing i now. So j is the next place we need to put a new item in the array. And it's looping through the rest of the result, and it's putting a 0 into all of the items that come after it. So we're going to copy over all of the values from nums that aren't 3, so 5 and 4. There's still two other places. This is explicitly putting a 0 in there. However, if you remember, when we initialize or instantiate an array result with int, it's automatically going to put 0s in there. So technically, we didn't have to do that. But it gave a little complication to what you're using j for afterwards. And then, if you wanted to put the rest of the values at negative 1, then this would be the loop you would do. You'd just say result sub i equal negative 1. Okay, last one. Kind of building off the the previous one. Now, we have two arrays, nums1 and num2, named very nicely to help a little bit with that. They are coming together, and they're going to create a new array called result, with an interleaving of the two of them. In this case, I picked the numbers kind of nicely to sort of make it easy, 2, 3, 4, 5, 6, 7. And you can see, nums1 is 3, 5, 7, 9. And num2 is 2, 4, 6, 8. So we take nums2, the first item, then nums1, the first item, then nums2, the second item, nums1, the second item, go on and on. That's what's supposed to be there. And here's our correct answer on the right. Again, this is one of those things of j is keeping track of the where we should be indexing into result. i is keeping track of where we index into nums1 and, in this case, nums2. Do they increase at the same rate? And the answer is, in this case, j is going to increase twice every time i increases once because now we're taking two items and we're sticking it into result. Rather than sometimes taking an item and putting it into result. So new array of 2 times the length. Actually, I decided to do the link of nums1 and nums2. This I looked up some solution for coding that one in. This was kind of interesting, I stole it. So we're looping over half of result. That's the same thing as either nums1 dot length or nums2 dot length. So feel free to ask your students if that would be the same. It is. I think nums1 dot length is better, but that could be interpretation. And then, j again is the next index of the result that we want to put something in. So essentially, it's going to increase two times every iteration. So we'll take nums2 sub 0, and we're going to put it in result sub 0 and immediately increase j by 1. So now j is 1. So nums sub 0 goes into result sub 1. And then we increase it to 2. So it's exactly the opposite of the last one. And it will interleave these two arrays. Careful to note here, this code will only work on arrays of the same length, interleaving them. It's more complicated if you want to interleave two arrays that aren't of the same length.