Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

Archive for December 2016

Implement the `cd` command

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

Next greater element in array

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

Buy and sell a stock k times

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

Pots of gold

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

Lego blocks challenge

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

Longest Increasing Continuous Subsequence

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

Distributed system for data security and data privacy – Part 1

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

Sieve of Eratosthenes in interval

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