- My name is Abdul Rahim. I am a Computer Science Engineer from India.
- I love tech, and I love to talk about tech. Below, you fill find some of my blogs and articles.
Leetcode 715: Range Module in 6 line python. The epitome of python sorcery demystified
Leetcode 715. Range Module is one of the most convoluted problems on leetcode. And your confidence is further shattered when you find out, that it can be solved in just 6 lines of code. Upon seeing these 6 lines, you realize that this is nothing less than a rosetta stone. In this blog post, I will run the code through all possible edge cases by hand. Range Module A Range Module is a data structure that tracks intervals of numbers using half-open ranges [left, right). It supports adding, querying, and removing ranges efficiently. ...
How to use psql
Launching psql session In my previous blog, I described how you can set up a postgresql server. In this post, we will learn, what are some of the basic commands in psql and how can we efficiently interact with it. To launch the psql terminal interface, you need to log into the postgres user or the username that created the postgresql server. This can be done using the su command. ...
How to deply a postgresql server
Database Cluster A database cluster is a collection of databases that is managed by a single instance of a running database server. In this post, we will talk about how to create a database cluster. Prerequisites The data created by postgresql is stored on the host file system in a directory called data directory. You can choose any directory to be data directory for example: /usr/local/pgsql/data or /var/lib/pgsql/data. The data directory is initialized using a program called initdb which comes with standard postgresql-server installation. ...
Leetcode 775: Global and local inversions solution
When nums[i] > nums[j], it is global inversion. Local inversion is special case of global inversion with j=i+1 Consider the array: [0,1,2,3,4,5] If i swap a random element by 2 positions (either to left or right). I will always create 2 inversions. Likewise, if I swap a random element by 3 positions. I end up creating 3 inversions. Similarly if I swap an element by 4 positions. I end up creating 4 inversions. ...
Leetcode 698: Partition into k equal sum subsets: The art of recursion: mastering double recursion in a single function
We need to divide the array nums into k subsets such that the sum of each subset is same. $$ k \times sum\ of\ each\ subset = total\ sum\ sum\ of\ each\ subset = total\ sum\ \div k\ target = total\ sum\ \div k $$ Now our task is to find all the k subsets in nums whose sum is target. My idea is to structure this as multi-level recursion. We first try to find the $$k^{th}$$ subset, then $$(k-1)^{th}$$, then $$(k-2)^{th} …$$ until there is only one subset left. The last subset will naturally sum to target. You can only go to $$(k-1)^{th}$$ level when you are able to successfully find $$k^{th}$$ level subset, ...