Random Wits

Life is too short for a diary

$ random wits
├── tags

├── bookshelf

├── resources

├── quotes

├── habits

└── about

Thu 04 Nov 2021

Ternary String solution Codeforces - 1354B

Ternary string is an interesting problem that could be solved using two pointers techniques. It's a convenient way to keep track of multiple indices. This helps in making decisions based on two values.

You are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once. A contiguous substring of string s is a string that can be obtained from s by removing some (possibly zero) characters from the beginning of s and some (possibly zero) characters from the end of s...

Continue reading → Tags : codeforces two pointers java python

Tue 02 Nov 2021

Coin Change solution leetcode

It's one of the most popular questions on leetcode that seems very easy at first. Coin change is a classic dynamic programming problem. I will proceed with an obvious (albeit wrong) solution and subsequently proceed to an efficient correct solution.

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. You may assume that you have an infinite number of each kind of coin...

Continue reading → Tags : programming leetcode code dp java python

Fri 01 Oct 2021

Dear Vishi, is snoring innocuous?

I was an intern working in Upstate New York. Public transport required hopping multiple trains & buses and was woefully tedious. I found some other interns who were willing to split the fare with me for Uber. Even a ride in Uber consumed more than two hours. Occasionally I used to steal a quick nap. After a siesta of a few hours, I had always woken up with a gaggle of laughter. My peers often pulled my leg, "You were snoring like a pig". However, I dismissed my faux pas as just a mere nuisance.

Recently I was listening to a clubhouse talk about snoring1. I always believed that snoring was innocuous. However, I learned that snoring might be a symptom of a disorder like sleep apnea. Since most of us snore or are more likely to snore in the later part of our lives, it would be prudent to delve deeper into the understanding of snoring...

Continue reading → Tags : snoring sleep apnea diary rambling