Pascal’s Triangle

Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] The logic becomes apparent just by looking at the pattern, but the property of pascal’s triangle comes from coefficients in the binomial expansion. nCk = n-1Ck + n-1Ck-1 and nC0 =1

Cut Painted Cube Puzzle

Cut cube

Puzzle: A solid, four-inch cube of wood is coated with blue paint on all six sides. Then the cube is cut into smaller one-inch cubes. These new one-inch cubes will have either three blue sides, two blue sides, one blue side, or no blue sides. How many of each will there be? Puzzle Solution: Subtract Read More →

Secret Mail Problem

Puzzle: A wants to send a secret message to his friend B in the mail. But C (A’s Friend), who A don’t trust, has access to all A’s mail. So A put his message in a box with a lock. But A is not allowed to send a key! How can A send his message Read More →

Set every cell in matrix to 0 if that row or column contains a 0

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. This problem should be solved in place, i.e., no other array should be used. We can use the first column and the first row to track if a row/column should be set Read More →

Grofers Interview Experience – Set 1

Recently I am interviewed for Grofers SDE-1 position in Gurgaon. Round 1 (40 mins) Thorough discussion about the projects. My major work was on LAMP stack and since the projects were live, so the interviewer kept on grilling me. Questions on the database, challenges faced, control flow were asked. He even asked the implementation of Read More →

Urbanclap Interview Experience – Set 1

I applied through recruiter. The process took two days and Questions asked was both algorithm based and design based.Interviewer was very Helpful and Friendly.Culture and Working Environment is very Nice. Interview Questions: Q1. Intro about me and my current work. Q2. Work experience in android. Q3. Asked me to tell about the app I am Read More →

Count Number of Bits to be Flipped to Convert A to B

Suppose, I have two numbers A and B. I need to find out how many numbers of bits needed to be changed to convert A to B. Like: A = 1101101 B = 1011011 ^^ ^^ Here, we need to change 4 bits to convert A to B How can I do this? Solution: 1. Read More →

Union and Intersection of two Linked Lists

Given two Linked Lists, create union and intersection lists that contain union and intersection of the elements present in the given lists. Order of elments in output lists doesn’t matter. Following are simple algorithms to get union and intersection lists respectively. Intersection (list1, list2) Initialize result list as NULL. Traverse list1 and look for its Read More →

What are the underlying data structures used for Redis?

Here is the underlying implementation of every Redis data type. – Strings are implemented using a C dynamic string library so that we don’t pay (asymptotically speaking) for allocations in append operations. This way we have O(N) appends, for instance, instead of having quadratic behavior. – Lists are implemented with linked lists. – Sets and Read More →

Redis Tutorial

Redis, developed in 2009, is a flexible, open-source, key value data store. Following in the footsteps of other NoSQL databases, such as Cassandra, CouchDB, and MongoDB, Redis allows the user to store vast amounts of data without the limits of a relational database. Additionally, it has also been compared to memcache and can be used, Read More →

Edit Distance – DP Problem

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a character b) Delete a character c) Replace a character Input: str1 = “cat”, str2 = “cut” Output: Read More →

Graph – Breath First Search

breath first search

Below is a simple implementation of a graph and breath first search. The key is using a queue to store nodes. 1) Define a GraphNode 2) Define a Queue 3) Breath First Search uses a Queue Output: value: 2 value: 3 value: 5 Find value: 5 value: 4