Posts

Showing posts from April, 2016

Given dictionary words, find words matching the given pattern

Image
Problem Input was given as  List dict = new List (); that contains a list of 10000 words. Find all the words that match the given pattern without regular expressions. Ex : You are given a pattern like (h*t). The words matching it would be (hot, hit, hat, etc.)

[K9 keyboard problem]Finding the words by ranking - updating

Image
Problem You have a list of words with ranking. Now you need to create a function that will take this list as input and provide a way so that a T9 keyboard can provide three top results of probable words based on rankings for the numbers punched in. To help the understanding here is the picture of T9 keyboard. Figure 1: example T9 keyboard For example, given the list words with ranking: [ ( "test", 13 ) , ("tax", 7), ("tom", 50), ("text", 100), ("top", 79),("tub", 101), ("tap", 3))] Following input from the T9 keyboard, should return the following output. key = 8: [ (tap, 3)(tax, 7)(test, 13)] key = 82: [ (tap, 3)(tax, 7)] key = 83: [ (test, 13)(text, 100)] key = 86: [ (tom, 50)(top, 79)] key = 2: [ ]

Placing N queens in N x N Chess board

Image
Problem In $N \times N$  chess board, you have to arrange N queens such that they do not interfere each other. Following is how you define interference of queens.  1. Two queens cannot be on the same diagonal  2. Two queens cannot be in same horizontal or vertical line  3. Queen can jump like a knight. So, two queens cannot be at a position where they can jump two and half steps like a knight and reach the other queen.  You should return the possible ways to arrange N queens on a chess board. 

Moving zeros in the array to the left

Image
Problem  Push all the zero's of a given array to the end of the array. In place only. Ex 1 , 2 , 0 , 4 , 0 , 0 , 8 becomes 1 , 2 , 4 , 8 , 0 , 0 , 0. No additional allocation of array is not allowed. Everything should happen in place.

K way merge problem

Image
Problem Assume you have very  K large arrays of integers stored in the Disk. It is so large that I would not fit into your computer memory. You need to write the application that merge all K large arrays into sorted one list and store it in the disk. Example, say the memory size, K = 6. Your program should be able to merge the following three arrays. Note that each file has sorted list of integers.   File 1  = { 3 , 7 , 9 , 15 , 35 };   File 2  = { 2 , 8 , 45 , 60 , 70 , 100 };   File 3  = { 5 , 6 , 50 , 101 , 110 }; You need to write a program that merges the arrays into one array with all the numbers sorted in ascending order.

Mapping the donut orders

Problem [reviewed on 2022/03/27] You are given the two array of strings: dountType: the first one is donut name and the second one is donut type [ [ "crullar", "vegan"], [ "beignet", "coffee"] ] order: the first one is the name of the people and the second one is donut type. [ [ "jose" , "vegan"], [ "john", "coffee"] ] You need to write the program listing the following output. [   ["john", "beignet"], ["jose", "cruller"] ] Each person can like either one donut for all donuts. If a person like all donuts, the input will be like below: ["Adam", "*"] In that case, the output should be [ "Adam", "beignet"], ["Adam", "crulller"] Note the output is sorted primarily by the name and secondarily by the donut name. You need to implement the following method: # c++ vector < vector < s...

Merging partially sorted arrays into one array

Problem   Given three arrays of integers, each of which is sorted, write the program that merges three arrays into one keeping the integers sorted.  Example inputs:   arr1  = { 3 , 7 , 9 , 15 , 35 };   arr2  = { 2 , 8 , 45 , 60 , 70 , 100 };   arr3  = { 5 , 6 , 50 , 101 ,  110 };

Evaluating the reverse polish notation

Problem Given the list of strings consisting of the asthmatic equation expressed in the Reverse Polish notation. Write the program that evaluates the equation and returns the result. Example:     For { "4" , "1" , "+" , "2.5" , "*" }, output =12.5     { "5" ,  "80" , "40" , "/" , "+" } = 7

Printing binary tree

Problem Write a function to print the rows of a binary tree, terminating each row with a carriage return.

Produce the non-repeating string from a given string [updated]

Image
Problem   Rearrange characters in a string so that no character repeats twice.   Input:  abcccddaaabc   output:  cacacbadcdab

Finding unique events in the calendar [reviewed]

Image
Problem Find the maximum number of non-intersecting events in a Calender For example. given list of events each of which contains start date and end date as below: { [1,6], [1, 3], [1, 4], [5, 6] , [6,10], [9,10], [17,18] }. In this case, choosing the following events produce the maximum non-intersecting events. { [1, 3], [5, 6], [9,10], [17, 18] } Therefore, 4 should be returned.

Finding the valid letter sequence [reviewed]

Problem  There's a new language which uses the latin alphabet. However, you don't know the order among letters.   You receive a list of words lexicographically sorted by the rules of this new language. From this list, derive one valid particular ordering of letters in the language. For example, given list of words, { "abcdefo", "begz", "hijk", "abcedefgh", "ikom"} One valid sequence would be {abcdefom}.

How to find a sequential sub array which has the biggest sum [reviewed]

Image
Problem Given a number array, including positive and negative numbers, the question is to find a sequential sub array which has the biggest sum and the time complexity is $O(n)$, For example, [1,-2,3,10,-4,7,2,-5] is an array, and the sub array [3, 10, -4, 7, 2] has the biggest sum which is 18.

Finding the sequential sub array totaling to the given number[reviewed]

Image
Problem Given an array of integer A = {23, 5, 4, 7,2, 11}, and the length N, and target sum, S, write the algorithm that tells whether the sub array $A_{sub}$, where $\sum_{i=k}^p A_{sub} (i) = S$. For example, If N = 3, and S = 13, it should return sub array, {4,7, 2}.

Classic two sum problem

Problem Given the array of integer, A = {1, 6, 8, 2. 7}, and target sum, 9, you need to write the problem to tell where there are two integers whose sum equals 9. 2022-03-22: Additional constraints How will you change your algorithm if the input has duplicate values and you can't use the same values twice? You should return all matching number pairs. A = {1,3,3,5,7,8,4,4}, target sum 8 [ [3,5], [4,4]]

Finding nth expressible numbers [reviewed]

Image
Problem Given set of the prime numbers, P , find the nth biggest number that can be  expressed with the numbers in P.  e.g. prime set = {2, 3} ,  expressible numbers = { 1, 2, 3, 4, 6 .. } , Given N = 3, the 3rd largest expressible number is 3.