Growing up, I knew pretty early in my life that I wanted to pursue Computer Science as a career. Naturally, I wanted to go to the best schools in India that offered this course — but I couldn’t make it through their entrance exams.

That was a huge bummer for me. For a brief moment, I thought I had let myself and everyone else who supported me down. But looking back I think getting into my dream university was the **best thing that never happened to me**.

Because I didn’t go to my dream university, I thought I had to…

Lockdown made me get into working on my side-projects. I obviously wanted to be successful, so I started reading a bunch of business books side by side. A common theme I came across all these successful stories was the “luck” factor.

“I was there at the right place right time”.

Being an engineer, my first thought was “Can I hack luck? Can I do something to optimize for more luck?” Obviously you can’t control luck. Such events are quite random, but what you **can** do is increase the surface area so you are exposed more to such events.

The amount…

In one of our ruby project, we are using AASM gem.

This gem lets you build a finite state machine for Ruby objects. We usually use it with ActiveRecord to persist the “state” of an object.

This gem also provides simple API methods to switch the states of the object. The biggest advantage of this is that it prevents moving to invalid states, and thereby builds confidence that there can’t be any invalid transitions.

However, I found out in our rails app this wasn’t the case. There are quite a lot of people who contribute to our project, and most…

I was super new to Ruby and the Rails magic scared the shit out of me. Understanding how objects work in Ruby

was crucial to writing good software.

Weird thing about ruby is that the object can adopt behaviors that are not defined by their classes, which is the central defining principal

in Ruby programming language. It’ll make a lot of sense once we understand how objects work here.

Let’s get started.

Every object in ruby needs to know how to respond to the message sent to it.

class Person

def initialize(name)

@name = name

enddef speak

p “#{@name}…

How to think about recursion questions:

The best way to think about recursion questions is to think in terms of Mathematical Induction.

From Wiki:

`Mathematical induction is a mathematical proof technique used to prove a given statement about any well-ordered set. Most commonly, it is used to establish statements for the set of all natural numbers.`

To solve recursion questions more intuitively we should think in terms of MI.

Here is how we prove a particular formula using MI:

**The basis (base case)**: prove that the statement holds for the first natural number n. Usually, n = 0 or n…

My 2 month internship at Flipkart is almost over. It was such a wonderful experience. I got to work on a very impactful project with a super awesome web team (People who built Flipkart Lite).

A tiny glimpse of the impact of my work: Flipkart’s mobile product pages will load up under 3 seconds even on a 2G connection ( visited via Google Search). This is a massive improvement of **4X in loading time**.

It will be seen by millions of people who visit our website via Google search results and since it’s powered by Accelerated Mobile Pages(AMPs), its…

O(n) solution would be to reverse half of the linkedlist and then keep two pointers (starting from the beginning and starting from the mid), keep checking if values in the nodes are same.

You’ll have to be extra carefull with the odd/even length of the linkedlist

class Node(object):

def __init__(self,value):

self.value = value

self.next = None

'''

[1,2,2,1]

l = 4, from l = l/2

[1,2,3,2,1]

l = 5, from l/2+1

'''

class LinkedList(object):

def __init__(self,node):

self.head = node…

I got this question in my Assembly lab. I had to code this up for 8086 processor. But I’ll be writing about the approach here.

If `r` is the square root of `X`, then r*r == X.

We can use the binary search aproach to search for this number `r`, since it would lie between [1,X].

Thus, if r*r< X, then we can search for the number in upper right of the function?

If r*r > X, then we should expect the square root to be on the left side of the function?

lower_bound = 0

upper_bound = len(A)while lower_bound < upper_bound:

mid = (lower_bound+upper_bound)/2

if mid*mid == A:

return mid

if mid*mid < A:

lower_bound = mid+1

ans = lower_bound if mid*mid > A:

upper_bound = mid-1

return ans

So, the question is to find the range of the number in a sorted array.

Eg: in a list [1,2,3,4,4,4,4,4,4,5] , the range of 4 is 3 to 9.

To get O(log n) we’ll use Binary search. We’ll actually use it twice to find upper and lower range.

To get the lower range, we would want to slide to the “Left” of the array overtime (Since its sorted). A slight modification in Binary search would give us the left most value:

`while lower_bound < upper_bound:`

mid = (upper_bound+lower_bound)/2

if B <= A[mid]:

upper_bound = mid

else:

lower_bound= mid+1

(upper_bound +…

So, I came across this question recently which got me thinking for a while.

It’s easy to track frequency in a hash-table and spit out the number whose frequency is zero in O(n). But, we can’t use additional space.

But, as its mentioned in the question, the array’s length is equal to the range of the number.

This can help us use the input array as the hash-table.

Here, for each number in the array, we’ll use it as the key and put value equal to the number itself.

So, to represent if we have numbers 1 to 4 in…

Software developer with a passion for writing pragmatic code.