Tricky Questions

Solution to find Interleaving of Strings

Introduction This post is an enhancement over one of the previous posts where the task was to find if a given string C is an interleaving of strings A and B. To know more about the problem description, please visit the previous post Solution The previous solution is a iterative solution which requires lot of space. Here we will discuss a recursive solution. Hopefully with small code foot print. Before we jump into the code, let us understand the idea behind the solution. Here are the example Strings A, B and C A -> abcd B -> ade C -> abadcde The recursive algorithm...
Read More

Interview Question – Sorting Time Strings

Introduction This is a pretty famous problem asked in most of the interviews, "Sorting the dates". This is not a complicated one but sometimes, it becomes real confusing or starts giving unexpected results, if not properly taken care of. To learn more about similar problems, please visit the Interview Section. Do not forget to use the Subscribe feature on the right to get updates on new articles. Problem Statement- Sorting Time Strings You are given an array of Time objects in which the times are in the following format "13:24:56.123" i.e. "HH:mm:SS.Z" and you need to sort them in ascendin...
Read More

Interview Question – Pirate and the Gold Chest

Interview Question – Pirate and the Gold Chest : Once there were five pirates, each of them equally rational, intelligent and greedy. The pirates can be numbered as P1, P2, P3, P4 and P5 such that P5 has 1 years of service experience, P4 has 2 years of experience, P3, P2 and P1 has 3, 4 and 5 years of experience respectively. One day they find a chest of 100 gold coins and they decided to divide it among themselves. Everyone being equally greedy wanted maximum profit, so they decided for the following solution: 1) Each pirate will get a chance to propose a distribution rule, and then a ...
Read More

Interview Question – Find top three horses

Interview Question - Find top three horses : You are given five race tracks and twenty five horses.Find the minimum number of races you need to organize to find the fastest three horses. Here five race tracks means that only five horses can run at a time. Solution The trick to approach these type of probelm is to consider the corner cases, most of the times what seems obvious is not what is true. Lets name the five tracks as T1 , T2, T3 , T4 , T5 and we organize five races in the beginning Let us say that we have the horses named from A - Y. Lets organize the below races on the ...
Read More