So, let us do something different now. So, let us go that paragraph that we had. So, if you remember, we wrote down the paragraph
as one word per card. Kept in a sequence but. Now, we have them in the same sequence and
what we had done was I think we had put the punctuation with the word so for instance,
“It was Monday morning”. This was the first sentence and the sentence
ends with the full stop. So, the full stop was kept with morning. So, actually we can go through this and we
can kind of identify where the sentence is end, provided of course it in the correct
order which it is now. So, now what can we do with this? If you know where the sentence ends, then
an interesting question that we can ask is, what is the longest sentence in this paragraph? So, what is the longest sentence means that,
longest defined as the one which has the most number of words, let us say. So, wherever a sentence starts, we should
start counting the words. Start counting the words. Wherever a full stop comes, we have… of course, also count the longest sentence
in terms of number of characters in the words and add it up, but for moment, let us just
count it. So, let us count the words. So, when we start counting when we see a sentence
starting that means, after a full stop, we start counting. When we hit a full stop, the sentence is over. Over. So, we have… we have the number of words in that sentence. And then we have… We have to keep that aside and keep the count. When we come to the second sentence, we have
to start again. Yes. We have to because it is a new sentence. Correct. And then we start counting again the words
and then when we hit a full stop, at that point again we have a count for the sentence. So that count has to be kept aside. So, you are saying we have to keep separate,
remember the count of each sentence, but… and then if there are 4-5 sentences, then
we will keep 5 counts, we will keep like that and then we will take all those 5 counts and
find out which of those counts is the highest like what we did just now we found the maximum
total, like that we will find which of the counts is highest. And that will tell us which is the... But if it is a very long paragraph, will not
there be many counts, I do not know how many sentences there are in this I think there
must be a better way to do this? What is the better way to do this? I mean, they we have to keep track of the
counts of all the sentences and... So, when we were doing the marks, actually
we only kept track of the maximum marks that we have seen so far. We only needed one variable, it did not matter
that there were 30 students in the class or 100 students in the class, we never needed
to remember anything except compare the next mark with the previous maximum. maximum. So, can we do that here? When so which means that here we are looking
for the maximum count, count, count being the number of words in the sentence. Yes. So, if you are looking at the maximum count,
then we need only keep that maximum, maximum count, maximum number of words in the sentence
count. So, what I suggest is that, we keep the number
of words that we have seen so far, the longest sentence we have seen so far. The word number of words in that. Then each new sentence we count that sentence
from scratch, we start from the beginning and count. When we get a number for that sentence… we compare it with the… either we update it or we skip it. Like we did earlier, update and skip. So, we never actually have to remember all
the sentences. We do not need to keep track of the sentences
in this one, this particular problem. So, let us try that. Let us try that. So, what did we say we will do, we will start
with a variable which is. So, let us call it longest. longest. Longest and initially we need to set it to
some value. let me call it longest sentence, so, remember
what it is. Longer sentence. So, initially let us say that it is 0 because
we know that a sentence… Because a sentence has to have at least one
word, so 0. We can start with 0 and I am going to go through
the words, you tell me when we have hit the end of the sentence. As we do this, we count. So, do we keep count in another card… So, maybe I will do that. So, we need another variable, call that count,
count is keeping track of the number of words you have seen so far. We start with 0. So, we have first card. 1. second. 2. Third. 3. Next, now this one has a full stop. 4. So, our first sentence has 4 words in it. And as far as we know now this is the longest
sentence because our earlier estimate was only 0. So, now we say the longest sentence has 4
words. 4 words. Now what do we do with count? Do we cut it…. We have to start again… we cannot continue because it is new sentence. Yeah. So we just discard that earlier value of count
and start with count equal to 0 again. So, again. 1. next card. 2. next card. 3. next card. 4. next card. 5. next card. 6. This one has a, next card has a full stop. So we have seen 7 words in this sentence. 7 words in this sentence. Previous longest sentence had 4 words. 4, so we can… So, now replace... so, we can we replace 4 with 7 and again that
counting has to… Get reset. get reset to 0, because we are seeing a new
sentence now. We start again. 1. next one. 2. next. 3. next. 4. next. 5. next. 6. next. 7. next one, this has a full stop. 8. So, we got a slightly longer sentence, 8. So, we can replace this. So, I replace our… This length to the longer 7 by 8 and again
we reset.. We reset count to 0. And then we can start again. 1. next. 2. next. 3. next. 4. next. 5. next. 6. next. 7. next, this is comma not a full stop. 8. next. 9. next. 10. next. 11 next. 12. next, wow. 13. next. 14. next. 15. next. 16. next. 17. next. 18. next. 19. next. 20, I am running out of space. So it is 20, so this is of course much bigger
than 8 which was our earlier longer sentence. So now we say that our longest sentence has
20 words. Alright. So, I now need to keep counting. So, let us go back and so, the next sentence… set count to 0. set count to 0 again. I doubt that there will be another set as
larger than this one, but let us see. let us see. First one. 1. next. 2. next. 3. next. 4. next. 5. next. 6. next. 7. next. this is 8. colon. Next. 9. next. 10. next. 11. next, semi colon. 12. next. 13. next. 14. next. 15. next. 16. next. 17. next comma. 18. next. 19. next. 20. next. 21. next. 22. next. 23. next. 24. next. 25. So, the last sentence was actually the longest
and it had 25. So, this way what we have done is we have
just been keeping track of the longest sentence and each time we count a new sentence, we
restart the counting process. So, we keep counting again and again. So, we have one variable count which we keep
reusing. So, although on the card it looks like we
have kept track of the count of each sentence, each time we reset to 0, the previous count
is lost. Gone. So, we do not really know that the previous
one is 20 or 8 or 7 because we are just reusing so, we have 2 variables. We have the count variable which we keep restarting
each time and we have this longest sentence variable which is updated every time we see
a longer sentence, just like we did for the maximum marks in the last. So, this is a single iteration actually. In one iteration, we have managed to find
the longest sentence keeping track with two variables, one which keeps a count of a number
of the words in the sentence, another which keeps track of the longest sentence we have
seen so far. And we did not need to remember which sentence
contributed to the longest number of… The difference between the previous one and
this one was there the quantity we were counting the max was directly given to us in each card. Whereas, here we had first we had to calculate
that quantity by going across multiple cards. Then once we got it in one place, then we
compare. So, it is a little bit more complicated counting
than the previous one, but still it just combines what we have seen so far. Which is how to count cards and how to keep
track of the maximum. And the filtering also is very interesting
here because they are actually looking for the card which has a full stop in it. Yes. That is the first filter. Yes. The second filter is at that point we look
at the value of the count. Yes. which is a value of variable actually now. Yes. So, so far we have compared constant card
with a constant. We have compared in the last one, we compared
the value of the card with a variable. Variable. And now we are comparing the value of one
variable with another variable. With another variable. So, we are getting slightly more complicated
now in our computation. Very good, very good.