Find duplicate rows in a binary matrix - gfg

Just finished solving this problem of gfg, this is the POTD for 14-01-2024, wouldn't say that it was much interesting, mostly banal, but yeah this wasn't that easy to observe the logic behind this problem. 

Also I had made a mistake understanding the problem at first, it's the second time this week, I think that I really need to have my mind open while reading a problem, sometimes i do the blunder of ingnoring some of the details of the problem and rather going with my assumed versions of the problems.

The Cisco Problems... I think I'll be taking them tomorrow cause today I  am all packed till I hit the bed and I have no intention to extend my bed timing cause yesterday also I was 30 mins late to the bed, and I am trying to change my sleep cycle, it's a bit new to me but I'll manage I know. So... Cisco Problems tomorrow.

For this problem, well, if you are a beginner then you should think about the "ewww O(R^2C^2) approach" first unless you are a really really good beginner, in which case you would do the thing that I did in the very first attempt. 
Then after you would implement that and get a Time Limit Exceeded, which is not a bad thing at all considering that you are a beginner, at least you implemented something, that is not easy too.

But now think how to improve this??
Then comes the Programmer mind to play, you gotta see in the further matrix to see if this row had come before right?? But if we do that we get a TLE ;| So.... we STORE, we somehow remember that we had 3 instances of this row extra, so, when we'll be coming from the bottom of the matrix then we wud just keep decreasing that count.

Take this simple example of a string-- "abcaabc"
here after first 'a' we have 2 more 'a's and for b we have 1 more instance, similarly for c.

so a:2,b:1,c:1, 
this is what I did for a matrix, "storing the rows in the form of strings", this is the core of this problem statement.

for this str abcaabc, when we go from right to left, we see ohkk a 'c', fine update the occurences;
a:2,b:1,c:0, 
then 'b', update again, 
a:2,b:0,c:0,
now after seeing 2 'a's
a:0,b:0,c:0,
the rest chars will be ignored.
This is the only thing that we had to come up with in this problem statement.

I'll be going to college tomorrow, for today I have DBMS questions left, overall the day was quite fruitful, can't complain. 
See Ya!

Comments

Popular Posts