development

Python Coding Tips: Set & List

The following code snippets are very helpful during sets and list operations. Intersection of sets must check for valid case $ cat sets.py s1 = {1,2,3} s2 = {} # empty sets means the intersection is empty too! s3 = {} if set(s1) & set(s2): print(s1.intersection(s2)) else: print(“no intersection”) Result $ python sets.py no intersection […]

Read more
development

Python Collections: Counter

Many times we need to keep track of frequencies of unique keys. We can always use a dictionary but counter is more appropriate for its brevity. Python collections define the counter class. Counter works on any iterator and generates a count of elements. So it has a natural use case on the list 🙂 from […]

Read more
development

A New Tool to Post WordPress Blogs

A New Tool to Post WordPress Blogs I’m starting to use Google Docs to prepare blog drafts and post them through WordPress Desktop App. Pros Linked with google account Advanced editor Cons It does not post a blog post; it saves the new blog post as a draft. Let’s try Code block for index, n […]

Read more
architecture, design, development

MVC Explained

MVC is an architecture to separate an application in three cohesive, loosely coupled verticals. Model: The data of your application and methods to access it. View: The final output/expected result. Controller: The interface that handles requests from the model I’m trying to map it to a Linux Filesystem (e.g. ext2). Model: The file system block […]

Read more
architecture

Guidelines for a System Architect

The system architect is key personnel to enable the success of an organization. From the book, Building Microservices, I learned the following worth highlighting nuggets: An architect defines the technical vision of an organization. This vision is compatible with the strategic goals (e.g. expanding markets, market segments, etc) of the company. Taking an example of […]

Read more
development

Find Number with More Than 25 Percent Frequency In Sorted Array

Leetcode Element Appearing More Than 25% In Sorted Array class Solution(object): def findSpecialInteger(self, arr): “”” :type arr: List[int] :rtype: int “”” if len(arr) > 8: return self.getMostFrequentNumberOptimized(arr) return self.getMostFrequentNumber(arr) def getMostFrequentNumber(self, arr): counter = {} for n in arr: if n in counter: counter[n] += 1 else: counter[n] = 1 targetPercent = (len(arr) * 25)//100 […]

Read more
development

K Weakest Rows in a Matrix

Problem The K Weakest Rows in a Matrix Solution Uses Binary search to count 1s Uses heap to keep k weakest rows It naturally satisfies the condition for weak rows with the same number of soldiers. The smaller index row is processed first and hence any next row would not get pushed to the heap. […]

Read more
development

Number of 1s in a sorted array

Problem Count number of 1s in a sorted array. e.g. [1,1,1,1,0,0,0,0,0,0] Code def countOneBS(row, start, end): if row[start] == 0: return 0 if row[end] == 1: return end – start + 1 # The mid is dependent on the index of start mid = start + (end – start) // 2 # print(“mid=”, mid, “start=”, […]

Read more