DEV Community

Mukilan Palanichamy
Mukilan Palanichamy

Posted on

My journey in competitive programming

Hi, Folks! Today, I solved three problems on LeetCode: Moving Stones Until Consecutive II, Permutation in String, and Boats to Save People. We didn't require any complex data structures for solving these problems. We rather concentrated on finding the proper logic. The development of logical solutions is a byproduct of practice.

In both Moving Stones Until Consecutive II and Boats to Save People, the first step is sorting the given input arrays. Sorting makes the logic in both problems a lot simpler.

We use the sliding window method to solve the problem of Moving Stones Until Consecutive II. For this, we should calculate the maximum moves by making the smallest stone move toward the left and the largest stone toward the right until the stones are consecutive. We can then find the solution this way.

In the problem Permutation in String, we can use a dictionary to store the frequency of characters in the first string. We can traverse the first string with a window length equal to the length of the second string using the sliding window approach. Then, for each slide, we check whether it forms a permutation based on the character frequencies. This is how we can solve this problem.

In the problem Boats to Save People, we travel through the array using two pointers, one from each end. We keep on traveling until the pointers meet, checking whether the combined weight is within the limit. That's how we can solve this problem.

I hope my experience will be helpful.

Top comments (0)