Posts

Showing posts with the label Facebook

Finding possible permutation of N words [reviewed]

Problem Permutate a list of string  this question is supposed to permutate the characters instead of the whole string,  Here is input example {"red", "fox", "super" } the expected output is  r fs, rfu, rfp, rfe, rfr, ros, rou, rop, roe, ror, rxs, rxu, rxp, rxe, rxr, efs, efu, efp, efe, efr, eos, eou, eop, eoe, eor, exs, exu, exp, exe, exr, dfs, dfu, dfp, dfe, dfr, dos, dou, dop, doe, dor, dxs, dxu, dxp, dxe, dxr

Pattern matching through regular expression [reviewed]

Problem Pattern Matching  ----------------  Characters: a to z  Operators: * +  * -> matches zero or more (of the character that occurs previous to this operator)  + -> matches one or more (of the character that occurs previous to this operator)  Output if a given pattern matches a string.  Example:  pattern:a*b  string:aaab b, ab, aab, aaab, ab  output:1  pattern:a+aabc  string:ab aabc, aaabc, aaaabc ..  output:0  pattern:aa*b*ab+  string:aab aab, aabab, aaaabbab  output:1  pattern: a+a*b*  string: a ab, aab, aaabb  output: 1  Valid Assumptions: Please assume that both the pattern and string input are valid

Parsing the php code

Problem Given a tokenized PHP file, give me a map from class to list of functions. Here is same PHP code. class Foo {     public $aMemberVar = 'aMemberVar Member Variable';     public $aFuncName = 'aMemberFunc';     function aMemberFunc() {         print 'Inside `aMemberFunc()`';     } function bob() { print "hi, Hi am functopm bob2 "; } } class Olivia { function say() { print "hi"; } } $foo = new Foo; class bogus ; Write the code to return the map of the class name to the list of functions.

Finding the minimum steps to reach {m,n} in the grid [reviewed]

Problem A robot has to move in a grid which is in the form of a matrix. It can go to  1.) A(i,j) --> A(i+j,j) (Down)  2.) A(i,j)-->A(i,i+j) (Right)  Given it starts at (1,1) and it has to go to A(m,n), find the minimum number of STEPS it has to take to get to (m,n) and write  public static int minSteps(int m,int n)  For instance to go from (1,1) to m=3 and n=2 it has to take (1, 1) ->(1, 2) ->(3, 2) i.e. 2 steps

Make the perfect balance on the balances in the room [reviewed]

Image
You have a room-full of balances and weights. Each balance weighs ten pounds and is considered perfectly balanced when the sum of weights on its left and right sides are exactly the same. You have placed some weights on some of the balances, and you have placed some of the balances on other balances. Given a description of how the balances are arranged and how much additional weight is on each balance, determine how to add weight to the balances so that they are all perfectly balanced. There may be more than one way to balance everything, but always choose the way that places additional weight on the lowest balances. The input file will begin with a single integer, N, specifying how many balances there are. Balance 0 is specified by lines 1 and 2, balance 1 is specified by lines 3 and 4, etc... Each pair of lines is formatted as follows: WL WR WL and WR indicate the weight added to the left and right sides, respectively. is a space-delimited list of t...

Implement the read4 method [reviewed]

Problem Implement read using read4 class ArbitraryIO { private :     // returns bytes read or 0, sizeof(buf) >= 4     // reads up to 4 bytes at a time into caller allocated buf     int read4( char * buf); public :   // IMPLEMENT:toRead > 4 or < 4 or = 4, buf allocated by caller, return number of bytes read   int read( char * buf, size_t toRead) {   } }; Your method should pass the following test cases: ------ test case  --- // assume reader is reading over ->  a b c d e f g h i j ArbitraryIO r; char buf[ 1024 ]; int x; x = r.read(buf, 2 ); EXPECT(x == 2 ); EXPECT(buf[ 0 ] == 'a' ); EXPECT(buf[ 1 ] == 'b' ); x = r.read(buf, 5 ); EXPECT(x == 5 ); EXPECT(buf[ 0 ] == 'c' ); EXPECT(buf[ 1 ] == 'd' ); EXPECT(buf[ 2 ] == 'e' ); EXPECT(buf[ 3 ] == 'f' ); EXPECT(buf[ 4 ] == 'g' ); x = r.read(buf, 1024 ); EXPECT(x == 3...

Managing the conference rooms with balancing the occupancy percentage

Problem Given the list of conference rooms with the capacity and the target occupancy percentages, write the program that maintains the balanced occupancy percentage across the rooms. Input: list of rooms { [30, 0.6], [50, 0.7], [90, 0.4]}, number of guests Output: list of rooms with balanced occupancy percentages across the rooms

Guessing the word from a dictionary [reviewed]

Problem Assuming you're playing one game that you need guess a word from a dictionary. You're given a machine you can try to guess the word, the machine will return how many characters has been matched by your guess. Design a system to crack the word.

Sorting the patient's files with three types: Low, Med, High

Problem   An efficient way to sort patient files in an array of just 3 types, "high-importance', 'med-importance', 'low-importance', which are in an arbitrary order(unsorted)   The output preference should start with the highest.   example: [high, low, low, med, high, low]

Finding sub array totaling the given sum (Knapsack variation)

Problem Given the array of integers, A, the target sum, S, and the limit on number of integers to use, K, write the program to return the K integers, whose sum equals, S. Example: A = { 1,2 ,4, 5, 9}, with K = 2, S = 6,  output  = {4, 5}

Shuffling the deck of cards perfectly randomly.

Problem Write the program to shuffle the deck of cards in statistically random order.

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.

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 };

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}.