/images/avatar.png

Reverse a Linked List

How to reverse a linked list Initialize null prev curr node pointing to head Change directions save curr’s next into a variable next point curr’s next pointer to prev Move the curr and prev nodes one step ahead prev becomes curr curr becomes next Repeat steps 2 and 3 until curr is NULL Infographic on Reversing a Linked List Code for reversing a linked list Python 1 2 3 4 5 6 7 8 9 10 def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: prev = None curr = head while curr: next_node = curr.

#271 Encode and Decode Strings

Link https://leetcode.com/problems/encode-and-decode-strings/description/ Solution I just used all the punctuations given by string.punctuation in python as the delimiter. Obvious flaw here; if the same kind of string exists in the actual string, it is going to read it as a delimiter. (It was one of those days. Tired + no motivation; but can’t miss two days in a row hehe) To combat that, there’s an approach which is agnostic to the type of delimeter Reference rather it sequentially looks for a number followed by a special character (@).

#49 Group Anagrams

Link https://leetcode.com/problems/group-anagrams/description/ Solution Generating a custom key function is necessary. The custom key function in this case initializes a vector of 26 zeroes each represeting a letter in the alphabet. Each zero will be incremented by 1 giving us the count of letters in the given word. Time analysis: All the strings in the input array are going to be tranversed once. O(N) where N is the total number of strings in the input array.

#128 Longest Consecutive Sequence

Todo: Explanation of solution Time complexity What patterns were applied - complement of target (two-sum problem technique) union find (for connected component) Link https://leetcode.com/problems/longest-consecutive-sequence/description/ Solution Code Python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 class UnionFind: def __init__(self, n_size): self.

#347 Top K Frequent Elements

Link https://leetcode.com/problems/top-k-frequent-elements/description/ Solution The first step is to build a hash map element -> its frequency. This step takes O(N) time where N is a number of elements in the list. The second step is to build a heap of size k using N elements*. To add the first k elements takes a linear time O(k) in the average case, and O(log1+log2+...+logk)=O(logk!)=O(klogk) in the worst case. After the first k elements we start to push and pop at each step, N - k steps in total.

How to use a Dockerized PgAdmin and make user management easy

We interact with databases almost all day long - consuming video content on the largest streaming service, chatting with your friend on the most widely used chat application or just poking your friend on the most powerful social networking site. When a company’s heart and soul rests in a database, as ours do at Riverus, it becomes mandatory to make it easily accessible not only to the engineering and data science team, but to the legal, sales and marketing team as well.

How to spin up a personal blog using Hugo - Part 1

Before we start, I just want to clarify what this article is and is not - Following is my experience of installing a Hugo blog to maintain my personal abode of learnings. This includes the hiccups I encountered along the way. Since I have set this blog up on Ubuntu 16.04, I’ll be documenting the steps I had to follow to spin up a satisfactory blog accordingly and eventually host it on Github Pages.

How I improved my typing speed and how you can too!

I was able to get hold of the data used in the following analysis, courtesy of Noah, creator and maintainer of TypeRacer Data, a third party information center for TypeRacer. Ever wondered what influences your typing speed? Well there are various resources which can help you polish your technique but there’s more to it than just touch typing and finger placement. Most of the time I am asked this question — how did I improve my typing speed to achieve a speed of over 100 words per minute?