DEV Community

Mukilan Palanichamy
Mukilan Palanichamy

Posted on • Edited 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 did not need any complex data structures to solve these problems. Instead, we focused on finding the right 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 approach to solve the problem Moving Stones Until Consecutive II. We need to find the number of maximum moves by having the smallest stone move toward the left and the largest stone toward the right, making the stones consecutive; then we get the answer 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 then traverse the first string using the sliding window approach for a window length equal to the length of the second string. Then, we check whether each slide forms a permutation based on character frequencies. This is how we can solve this problem.

In the problem Boats to Save People, we use two pointers that move along the array from both ends. We keep on traveling until they meet, and then check if the weight is within the limit. That is how we can solve this problem.

I hope my experience will be helpful.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay