Hello, everyone.
So in this video, we are going to discuss one more question, so let me explain you what is the question?
So you are provided with the map.
So you are provided with a map and this is the key and this is the corresponding value.
Similarly, this is the key and this is the value.
So this is the key and this is the value.
So you have a map of type.
Key is string key.
We have a string and it is a value.
Value is basically a list or we can see a vector already.
So value is basically a list of veterinary and list of string.
So each word is basically a string.
So we are given this map and we are given a paragraph, so we are given a paragraph, for example,
lion girls, leopard, dot, dot, dot, dot, dot, dot, dot, dot, dot, dot, dot, dot, dot,
beautiful, battered, dot, dot, dot.
And so this is a very long paragraph.
OK, and now what we need to do so we need to replace the words which are auguring in paragraph by dakis.
So what do we mean by this.
So for example, lion kills leopard lion.
So Lion is present here and what is its key.
But is the key for lion.
The key for lion is basically cat.
So you need to replace Lion Bichard similarly leopard.
So for leopard what is the key cat.
So you will replace leopard by cat and so on.
So Forwell what is the key is Océane.
So you will replace Will by ocean and so on.
So bad is not present anywhere.
So we will not replace Sharky's present.
So foreshock.
We need to replace it with Océane.
And so on, then beautiful then Pettit's better Betteridge we need to replace it by boards so replace
battered by bird and we keep doing this.
So this is your problem statement.
You need to replace all the words in the paragraph by their corresponding keys.
And now the question is how you can do this.
So what I suggest is you can post a video for five to 10 minutes and then think, and then try to think
of a solution.
So I hope you have both the video and think of a solution and and have given your full attention to
this problem.
So now let's discuss what can be the possible solution.
So first of all, what I'm trying to think it is so this is very difficult, right.
For example, you are given an outline, so how you will be able to find out the key for laying the
Keys card, what to do.
You need to arbitrate over this map and for each key, what you will do, you will iterate over this
basically list.
So forget you will trade over the list and we will compare line with the given word line and then you
will replace the word by card.
So this is a very, very lengthy process.
For example, foreshock or let's take the example of Petitt so far better.
What do you need to do?
You will migrate over this map for each key.
You will migrate over this list.
You will not be able to find Pettit's.
Then for the second key, you will Étretat with this list.
You will not be able to find Pettit's then.
Similarly, for the third, you will be able you will be searching this area, this list, and you will
be able to find Barret's and then you replace by board.
So I think this is a very, very, very lengthy process because we need to do this process for each
and every word.
So for the words, for example, beautiful, what will happen?
You will search here.
You will not find the word.
You will search here.
You will not find the word will search.
You will not find the word.
And it will basically keep searching.
And you will not be able to find the word beautiful and you will not replace since you are not able
to find the word beautiful, you will not replace it.
So it's a very, very, very, very lengthy process.
So one optimization that I can think right now is basically let's try to create a reverse map.
Let's try to create a reverse map of it.
So what do I mean by reverse map?
So I was told like this for line.
I have cared similarly for Tiger.
I have cared similarly for Leopard.
I have cared similarly for shock.
Get ants on some of the first battle.
I have this bird.
So I will prepare one map, I will prepare one map, and this map is of type string on my string keys,
a string, so key is a string and value is also a string.
So value is also a string.
Now, this will improve our searching.
How?
Because for line, if you want to search and nobody will do, you will simply search for the key, you
will simply search for the key.
And that this line you do not etrade, you will simply search for the key line and you will replace
the line by its corresponding value.
Similarly for kids, you just need to call the function search of map.
I think that search function or I think or dart find our dot count function.
So map map provides you the availability to search bickie.
Right.
So for apart will do, you will call the search function off map and it will return you the card.
Right.
So in this way we are improving our searching.
It is lot better than the previous searching because in this case we just need to figure out the world
and how we can figure out the word.
So there are spaces between them to just figure out the word, search this word in this map if the word
is present, replaced by the corresponding value.
Yeah, this solution will work.
This solution is going to work.
But there are problems with the solution and what is the problem.
So problem is, basically, you can see so in map, how many entries are there in this map, in the
input map, how many entries are there?
There are only three entries.
We have only three entries for this map, for the input map, and how many entries do we have in this
reverse map?
So one, two, three, four, five, six, seven and eight.
So we are going to have eight entries in the reverse map.
Now, let's see if this list, if this list is basically of the order 10 to the power six, this list.
Similarly, this list is like containing 10 to the power six items similar.
This list is continuing to deliver six items.
So what you are doing, what will be your size?
So you still have three entries in the map.
But if you will reverse the map, how many entries you are going to have?
10 to the power, six plus 10 to the power, six plus 10 to the power six.
So your map will become huge.
It will become huge.
It is going to take a lot of lot of memory, a lot of lot of memory.
And although we improved our searching but for improving the searching, we are taking a lot of memory
and we don't want that.
So this is the first limitation of this solution that your memory consumption will be huge.
There is one more problem with this approach and what's the problem?
So currently I am saying that the world is lying, but I never said that it will contain only one word.
It can be a list of words.
For example, I have gathered and forget I have like lions and cubs, lions and their children.
Similarly, I can have like tigers and tigers or female tiger.
Right.
So I can have.
So currently you have seen only one word.
What if we have a collection of words?
So if you have a collection of words and if you make a reverse map also so, for example, if you make
the reverse map, that is lying and cubs to get.
So in this paragraph, if the word is lions and cubs, then how you'll be able to figure out when to
stop, right?
There is space between this.
There is space between this and there will be space and also so how you will be able to figure out when
to stop.
So what he will do, what you will do, you will stop headlines, then you will consider lines and then
you will consider lions and cubs, then you will consider lions and cubs and something else.
Right.
There can be something else.
So, for example, lion cubs and we have one more entry in this, which is lions and cubs and something
else.
So basically, you will not be able to figure out when to stop.
So you will take a collection of one word in the paragraph, you will take a collection of one word,
then you will take a collection of two words, then it will take a collection of three words.
Then you will take a collection of four words and keep going on.
You will not be able to figure out when to stop.
So this solution that we have discussed has two major problems.
That memory conception is a lot more.
And this solution will only work when you have only one word and not collection of word.
So here in the input, we are having only one word lion.
We have only one word tiger.
We do not have a collection of words.
OK, so these two are the limitation for the solution that we have discussed.
That is reverse mapping.
Your memory consumption will increase and also this reverse mapping solution will only work if you have
a single word and not a collection of words like this.
If you have the collection of words, you will not be able to figure out when to stop in the paragraph
while you trying to replace the word, you will not be able to figure out when to stop.
So these two are the limitation for this problem, for this solution, basically.
Now, in the next video, what we will do all basically what you should try, can we improve the solution?
So let me give you a hint.
We can definitely improve the solution and how we can improve the solution basically from the last few
lessons we are learning, particularly the structure, which is called Try So and I am discussing this
problem, then it's very obvious that private sector can be used here.
And now the challenge is basically how you will be using private sector for this problem.
So try structure will basically solve both of these problems, the memory problem and also the single
word problem.
So this video is getting Landi, so I will discuss the solution, the next video and you can also think
yourself how that can help us.
So this is pretty much that I want to discuss in this video.
So this is it, guys.
I will see you in the next one.
Thank you.