QotD (2016-Dec-05) – Minimum swaps

Minimum swaps to make two arrays identical Given two arrays which have same values but in different order, we need to make second array same as first array using minimum number of swaps. Examples: Input : arrA[] = {3, 6, 4, 8}, arrB[] = {4, 6, 8, 3} Output : 2 we can make arrB to same as arrA in 2 swaps which are shown below, swap 4 with 8,.. Read More

QotD (2016-Dec-01) – Build the smallest

Given a number N and string S of digits denoting a positive integer [ N < sizeof(S) ] , build the lowest number possible by removing N digits from S, without changing their order. Input The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains a positive integer N. The second line.. Read More

QotD (2016-Nov-30) – The Game of Hex

The game of Hex has been invented in 1942 by Piet Hein, reinvented in 1948 by John Nash, got its name in 1952 from a commercial distribution by Parker Brothers and has been popularized by Martin Gardner in 1957. It is similar to tic-tac-toe on a hexagonal 11×11 board. The blue player must make a connected set of blue hexagons from east to west. The red player must do the.. Read More

QotD (2016-Nov-29) – Sparse Similarity

The similarity of two documents (each with distinct words) is defined to be the size of the intersection divided by the size of the union. For example, if the documents consist of integers, the similarity of {1, 5, 3} and {1, 7, 2, 3} is 0.4, because the intersection has size 2 and the union has size 5. We have a long list of documents (with distinct values and each.. Read More

QotD (2016-Nov-28) – Jump

Minimum steps to reach end of array under constraints Given an array containing one digit numbers only, assuming we are standing at first index, we need to reach to end of array using minimum number of steps where in one step, we can jump to neighbor indices or can jump to a position with same value. In other words, if we are at index i, then in one step you.. Read More

QotD (2016-Nov-23) – Anagram words

Given a file containing a list of valid words in alphabetical order, and an input string: Q1. find all the valid words that can be generated using all the letters of the string; Q2. find all valid words when the letter of the string can be a wild card representing (a-z); Q3. find all valid words when you both ignore and consider the wild cards in the input string; Please.. Read More

QotD (2016-Nov-22) – Sub Sort

Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n – m (that is, find the smallest such sequence). Example Input: 1, 2, 4, 7, l0, 11, 7, 12, 6, 7, 16, 18, 19 Output: (3, 9)

QotD (2016-Nov-18) – Job schedule problem

There is a sequence of jobs which are interdependent. Meaning, you have to finish one or more jobs in order to proceed to the next one. Design an algorithm determine which job should proceed which one. Example: Jobs A B C D E F G C can start only after A and B D can start only after B E can start only after C F can start only after.. Read More