# Archive for December 2016

Problem statement Implement the cd command i.e. given a function cd(‘a/b’,’c/../d/e/../f’), where 1st param is current directory and 2nd param is the sequence of operations, find the final directory that the user will be in when the cd command is executed. Solution I am going to use a Stack to . . . Read more

Problem statement Given an array, print the Next Greater Element (NGE) for every element. The Next greater Element for an element is the first greater element on the right side of in array. Elements for which no greater element exist, consider next greater element as . For the input array . . . Read more

Problem statement Write a program to compute the maximum profit that can be made by buying and selling a share times over a given day range. Your program takes and an array of daily stock prices as input. Solution At any given day you can either make a transaction or . . . Read more

Problem statement Pots of gold game: Two players and . There are pots of gold arranged in a line, each containing some gold coins (the players can see how many coins are there in each gold pot – perfect information). They get alternating turns in which the player can pick . . . Read more

You have types of lego blocks, of sizes given as , and . Assume that you have an infinite number of blocks of each type. Using these blocks, you want to make a wall of height and width . The wall should not have any holes in it. The wall . . . Read more

Problem statement Given an array of numbers, find the number of pairs in an array whose difference is Input Format The first line of the input will contain and . The next line will contain space separated integers. Output Format The number of pairs in array whose difference is . . . . Read more

Problem statement Given an array of numbers, find the longest increasing continuous subsequence. Sample Input 3 4 1 2 3 3 4 5 10 99 100 80 Sample Output 3 4 5 10 99 100 Solution public static int[] longestIncreasingContSubSq(int[] arr) { int subSeqLength = 1; int longest = 1; . . . Read more

In the first part, I have described how one can design a distributed system for maximum security and data privacy. Now its time to provide a sample technology stack for such a system as well as a basic functioning prototype. Technology Stack Our architecture will make use of the following . . . Read more

Introduction Suppose you are building a platform, that integrates data of sensitive nature. Such a platform can be an IT-solution, like a web application, for clinical studies that enables patients and doctors to login and access the data, such as findings, demographic data or enter new information. Another example would . . . Read more

In a previous post I illustrated how we can enumerate all the prime numbers up to a given range using a well-known approach called Sieve of Eratosthenes. But what if we want to enumerate all the prime numbers within a given interval ? Instead of just crossing off multiples of . . . Read more