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.

Top comments (0)