Day1

My uni's fourth semester is over and summer has started. I was all set for resuming my competitive programing (CP). I was discussing this with one of my closest hostel mates, Monty. He basically guided me for the initial steps. I would also give a detailed guide for the steps sometime later, if someone needs one from me, lmao. While we were discussing a friend of mine Ravioli also tagged along and wanted to resume her CP with me. So we technically started together from today.

So the question we did was 1672B. on codeforces named "I love AAAB". 

I spent 2 hours just figuring out the algo and implementing it on code. Initially I figured out 3 conditions for the string to give an output YES as:

1. The length should be greater than 1.

2. The first letter should not be B and the last letter should not be A.

3. There should not be any two consecutive B's

Out of which first two conditions were correct but I had a feeling that the third one was wrong any way I implemented it to get a wrong answer on the testcase2. Then I thought and modified the third condition.

1. The length should be greater than 1.

2. The first letter should not be B and the last letter should not be A.

3. If there are n consecutive B's then there should be greater than equal to n consecutive A's before them.

This came from a thought that I might do some grouping in the string so that the substring that is grouped can be made using the good strings. 

Like AABAAAABBBAB can be grouped as (AAB) (AAAABBB) (AB).

But turns out in some cases even if a group is not formable from the good string then it can be formed by the good string if grouped along with the previous or the next group. 

Like AABAABBB although its grouping can be like (AAB)(AABBB) where the last group is non formable but it can be formed from (AABAABBB).

So an hour more and I was exhausted. So I took a hint and was finally able to find a great way to deal with this question. My grouping method was somewhat similar to that but complicated. 

The problem can be solved by assuming that A and B are nothing but open bracket ( and closed bracket ), deal it like a problem to check if a given bracket string is valid or not. But just with a condition that every ) should have a corresponding ( but every ( might not necessarily have a corresponding ).

I liked this a lot!

MORAL: Analogies can be made with the things that you have already studied.

Bye. Cheers!


Comments

Popular posts from this blog

Day5

Day3