Random Wits

Life is too short for a diary

$ random wits
├── tags

├── bookshelf

├── resources

├── quotes

├── habits

└── about

Posts Tagged “python”

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 → 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 → programming leetcode code dp java python

Thu 08 Apr 2021

How to Make(Or Lose) Money in Stocks Part1

Recently I finished watching web-series Scam 1992. It's based on story of Harshad Mehta, a famous Indian stockbrocker who made fortunes in stocks. Despite his iconic success & failure, the series rekindled my interest in world of "stocks". I guess the famous dialogue "Risk Hai Toh Ishq Hai" has stuck with me.

I still consider myself a novice in stocks. There's a no magic bullet to make money in stocks. However you can leverage scripts to reduce time to accumulate information. I'll share one such approach in helping buying or selling stocks...

Continue reading → stocks python finance money google selenium

Thu 10 Dec 2020

EnvCommandError in Windows using Poetry

Poetry is a great dependency management tool in python. It's better than managing a flat file like `requirements.txt`. There are also other great tools like pipenv. However I found poetry much simpler in resolving dependencies.

Recently poetry has been crashing on my Windows machine. However, I have not encountered this issue in other platform like Linux. Folks who are unfamiliar with poetry, below is a quick refresher...

Continue reading → windows python poetry bug

Fri 10 Jan 2020

Connect to an Oracle Database using kerberos with python

Jobs failed! Screamed an automatic failure alert in email inbox. Existing python scripts were failing in the server which fetched data from Oracle database. I wondered if the credentials had changed.

After few emails back and forth with the Support team, I discoverd that the server had been upgraded with Kerberos authentication. I have to modify my scripts to support kerberos authentication. I have to dig up more to understand more about kerberos...

Continue reading → kerberos projects python docker oracle database