Mar 16Dealing with mutable arguments in Unit TestsIf you pass a mutable argument and then try to unittest it with .assert_called_with(), you might run into problems. This issue can be confusing since it might seem like there is a bug with the testing framework (such as pytest), and many people have been led down that path. After digging deeper, I found the following article that explains the problem: https://docs.python.org/3/library/unittest.mock-examples.html#coping-with-mutable-argumentsPython1 min readPython1 min read
Oct 31, 2020Find the intersection of two lists in Python with Duplicates.>>> from collections import Counter >>> a = Counter([1,2,3,4,5]) >>> b = Counter([1,3,5,6]) >>> a &= b >>> list(a.elements()) [1, 3, 5]Python1 min readPython1 min read
Mar 14, 2020Leetcode 34This is an interesting problem involving Binary search. Here is the link to the problem — https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ class Solution: def searchRange(self, nums: List[int], target: int) -> List[int]: gLow, gHigh = 0, 0 low…Leetcode1 min readLeetcode1 min read
Feb 28, 2020Let's talk about Union Find.Union Find is a very interesting data-structure that makes a lot of graph problems easy to solve. — Let’s say, you have a set of N elements that are partitioned into further subsets, and you have to keep track of connectivity of each element in a particular subset or connectivity of subsets with each other. To do this operation efficiently, you can use the Union-Find Data Structure. There…Algorithms2 min readAlgorithms2 min read
Oct 10, 2019Leetcode 934 Shortest BridgeShortest Bridge - LeetCode In a given 2D binary array A, there are two islands. (An island is a 4-directionally connected group of 1 s not…leetcode.com Here is one of the solutions I understood, I am putting it here for future reference. I have added comments to make it easier to understand. # Start with picking the first 1 you can find. # Pick that point and start dfs to all all the edges for that…Programming2 min readProgramming2 min read
Nov 28, 2018Changing the swap size on Ubuntu 18.04.So one fine evening I find my budget laptop freezing up due to Chrome hogging up all the memory. Upon checking my RAM usage I figured that out of my 6.8GB of usable ram barely 500mb was left unused. By default ubuntu had set up a 2GB swap space, I…Ubuntu1 min readUbuntu1 min read