DEV Community

Rishitha Nallapureddy
Rishitha Nallapureddy

Posted on • Edited on

Problem solving journey - 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 initial step is sorting of given input arrays. Sorting makes the logic easier for 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. We calculate the maximum moves by moving 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.

For example, in the Permutation in String problem we can first use a hash map that stores the first string character's frequency. With the sliding window approach, this time traversing the first string, we take it with a window length similar to that of the length of the second string for each step we check if its characters constitute a permutation based upon the stored frequencies. Such is one way of working out such a problem.

In the problem Boats to Save People, we travel through the array using two pointers, one from each end. We continue traveling until the pointers meet and check if the sum of the weights is within the limit. That is how we can solve this problem.

I hope my experience will be helpful.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

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