DEV Community

Mukilan Palanichamy
Mukilan Palanichamy

Posted on

My journey in competitive programming

Today's Learning: Binary Strings, Parentheses, and Subsequences

Hey everyone!

Today, I worked on a few exciting problems that involved generating different combinations and sequences. Here's what I focused on:

Generate All Binary Strings
I began with generating all possible binary strings of a given length. The problem asked me to explore the concept of recursion and backtracking. Using recursion, I was able to explore every possible combination of 0s and 1s for the given length. It felt great to see how this approach works to solve the problem efficiently.

Generate Parentheses
Now, I come across the problem of generating all valid parentheses combinations. The constraint placed here is that the ending of every opening parenthesis of the sequence must be accompanied with a closing parenthesis. Which brings me to the implementation of backtracking and number tracking of opening and closing parentheses while constructing the valid sequences. It is funny how different constraints shape what is to be presented within the solution.

Image description

Print All Subsequences/Power Set
Finally, I worked on generating all subsequences (or the power set) of a given array. This involved iterating through the array and making decisions about whether to include each element in the current subsequence or not. This was a great exercise in understanding how to explore all possible combinations of elements and how to apply backtracking for that.

Image description

Top comments (0)