DEV Community

Rishitha Nallapureddy
Rishitha Nallapureddy

Posted on

Journal - 22-11-24

Hi, Folks! Today, I solved three problems on LeetCode : Bag of tokens, k-th smallest prime fraction, and Fruits into basket. As a Beginner, you need patience, and it’s okay to take a long time to solve problems. Depending on their difficulty, some problems may take days to solve. In the future, if you aim to solve a problem with in minutes, you need to spend more time in practicing. We should not get discouraged if it takes us a long time to solve a hard level or medium level problems.

If we invest really hours or even days solving a problem, the joy we feel once it’ solved is unimaginable. Try to stay curious and approach the problems as challenges rather than burdens. this will help you to enjoy the problem solving more.

For example, solving the kth smallest prime fraction problem took me almost 4–5 hours. Coming up with a logic itself took a lot of time. If a problem feels hard, don’t give up. Find resources to learn the concept related to problem, and then give it another try.

Bag of tokens : To solve this problems, we can use two pointers left and right. The left pointer will start from the 0th index, and the The right pointer will start from the last index. We can traverse the array of tokens with pointers, increment and decrement the value of power depending on values of the tokens. Create a variable ‘score’, to store the updated score at each step and we can return score as output. This is one way to 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