Hello, everyone.
So in this video, we are going to solve one more interesting question, and the name of the problem
is hotel reviews.
So let's quickly go to the description of the question and let's try to find out what is the question
and how we can solve this question.
So let me explain the question.
So we are given two things.
So we are provided with two things, first is basically a string, first is basically a string, which
is containing a list of good words separated by this underscore character.
So how many good words are present?
Three good words, cool ice and verify.
So first of all, what we do, we will split this into a vector of string.
And this are trusting what it contains.
So it contains three words.
First of all, is cool.
Second word is basically ice and the third word is basically verify.
Fine.
Now, this second input.
So this is Victor B and it is containing hotel reviews.
So what is this?
This is review.
Number zero, because indexing starts from zero.
So this is review number one, review one, and this is basically review to.
Right.
So, again, just like this, we are also going to split reviews zero in two, three words.
So there are three words present here for Australia's water.
Second word is basically is and third word in this review is basically coal.
Similarly, we will do the same for this.
The first word is basically called the second word is basically I's.
And the third word is basically drink.
Now, what is the problem statement, so problem statements is that you are provided with what is a
good word and you are provided with the reviews you need to return a vector of integers which contain
the original indexes of the review.
So what is the original index?
So this is index zero.
This is index one and this is index two in this sorted order of reviews.
So what do you mean by sort of reviews?
So see, for this review, I'm talking about reviews zero.
How many good words are there?
So how we can check that?
So is water a good word?
We can see here water is not present in this list of good words of water is not a good word.
Is is not present in this.
So is is not a good word.
Cool.
Yes.
School is a present.
So this review review No.
Zero is containing one good word.
And that good word is basically actually we can see cool is a good word.
Similarly, let's talk about review number one.
How many good words are there.
So I think there is only one good word here and that good word is basically ice cold and drink.
They are not good word.
Ice is a good word.
So one good word here.
We can see ice is present here.
So this is a good word for review.
Number two, let's talk about review number two.
How many good words are there?
So I think there are two good words.
Coal is a good word.
Wipha is a good word.
So coal is a good word.
Vafa is a good word.
So we can see review number zero is containing one good word.
Review no one is containing again, one good word and review number two is containing two good words.
Right.
So what should be our output, so we need to report our output as the indexes, first of all, the index
having the maximum good word.
So this index, too, is having maximum good words, which are to index number two will come first.
Then these two reviews are containing equal number of good words, one and one.
So it doesn't matter.
You can put zero and one or you can also put to one and zero.
Right.
So you can put 011 because review zero is containing one good word.
Similarly, review one is containing one good word so you can print their output like this or you can
print your output like this.
But it is given that since zero and one they have equal number of good words, they have equal number
of good words.
So your answer should be this and not this.
Right.
Zero is coming before one.
So that's why in the output only zero is coming before one and we can say zero is smaller than one.
So we need to preserve the original order of the indexes.
So this should be our output and not this.
OK, so we need to retain our output like this to and is the output we can see in the kitchen also it
is given that the output for discussion is basically.
Who 091 right, so that's how you will be able to solve this question and this is a very simple question,
but the problem is.
The searching part.
So how are you are going to search?
Like, if you want to search whether water is a good word or not, what you need to do, you need to
hydrate or this vector.
So remember, we have created a vector of three words called ice and verify.
For each of these words, for each of these words, what we need to do, you need to irate over this
at Idato this vector, and then you will perform the searching.
And this is the problem, right?
You are going to take a lot of a lot of time for searching.
And what is the solution?
Solution is to use a try.
We have discussed in our previous lessons try its best for searching.
And then this problem in this question, the main problem is searching time will be a lot more.
So we need to optimize our searching and for optimizing the searching.
What do we do?
We will use try.
So what we do, we will make a try of all the good words.
So we are going to make a try of all the good words.
So the first good word is cool ice and verify.
So cool I.
And by far.
So we will make a try of all these words, all good words, we are going to insert all the good words
in a try so that we can optimize our searching part.
And how you can build this dry, so what you need is you need to define the north structure, which
you have defined in our last review, and you need to write the code for the area function will basically
actually add Ice Adibi to the.
So how the add function works that we have discussed in our previous lesson and for all these words,
what need to do, you need to call the function such.
And the code for research we have written in our last review, we will search whether water is present
in this trial or not, Google is present in this trial, not ISIS.
Present and destroy or not verify is present in this trial or not.
So the main problem, the problem here was the searching problem.
Therefore, each word you need to arbitrate over this area to figure out how many good words are present.
But now, since we have a trial.
So I was searching parties optimized.
So that's what, guys, in this problem, the main logic, the main logic behind this problem is to
use try OK and for try, you need to write the code for our function and search function, which we
have discussed in our previous lessons rest.
The problem is very, very simple.
Just insert all the code words in a tray and for each word here, just call the search function and
maintain the count.
And then basically the remaining parties basically start the output according to the question demands.
Simple.
So this is a very simple problem and you can write the code for this problem yourself.
So, guys, this is it from this video.
I will see you with many more good questions in our next videos.
So this is it.
I will see you in the next one.
Thank you.