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. ...

August 4, 2025 · 3 min · abdul

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. ...

July 16, 2025 · 1 min · abdul

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, ...

July 16, 2025 · 3 min · abdul

Leetcode 745: Prefix and suffix search solution

For each possible word, we ask the question: What possible queries can lead to this word?. For example consider the word: abd. Below are the possible (prefix, suffix) queries that can return abd 1 2 3 4 5 6 7 8 9 10 (prefix, suffix) a abd a bd a d ab abd ab bd ab d abd abd abd bd abd d Now, given word.length <= 7. Each word can at maximum generate 7*7=49 such pairs. Can we store all of them in a hashmap? Yes, because the total storage = 49 * number of words = O(n) Which is acceptable for this problem. ...

July 16, 2025 · 2 min · abdul

Solution to Leetcode 687: Longest Univalue Path

This problem is very similar to lc543, which is about finding the longest edge path in a tree. You can just copy over that code, and add 2 lines in it. Here we are doing the same thing as in lc543, however, when we encounter a non-matching child. We treat it as null. For example, here the longest path at root node is highlighted below in red with 6 edges. ...

July 16, 2025 · 3 min · abdul