DEV Community

Rishitha Nallapureddy
Rishitha Nallapureddy

Posted on

Journal - 5-11-24

Hi, Folks! Today, I solved three problems on LeetCode: Moving Stones Until Consecutive II, Permutation in String, and Boats to Save People. To solve these problems, we didn’t use any complex data structures. Instead, we focused on finding the correct logic. Developing logical solutions comes with practice.

In both Moving Stones Until Consecutive II and Boats to Save People, the first step is to sort the given input arrays. Sorting simplifies the logic in both problems.

In the problem Moving Stones Until Consecutive II, we can use the sliding window approach to find the largest number of consecutive stones. To calculate the maximum moves, we move the smallest stone to the left and the largest stone to the right until all the stones are consecutive. This is how we can solve the problem.

In the problem Permutation in String, we can use a dictionary to store the frequencies of characters in the first string. Then, we use the sliding window approach to traverse the first string with the length of the second string as the window length. For each slide, we check if 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 traverse the array with the help of two pointers, one starting from each end. We continue to traverse until the pointers meet, checking if the combined weight is within the limit. This is how we can solve this problem.

I hope my experience will be helpful.

Top comments (0)