Posts

Showing posts from 2019

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

Finding the first missing number given the list with numbers [reviewed]

Image
Problem Given input [2,3,1,5,88,100], find the first missing number. All number are positive numbers. (1 - n) In the above example, 4 is the first missing number.

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.

Reordering the values in the binary tree.

Problem Given the tree as below, write the code that fixes the order of the tree such that the value of the parent is always larger than the value of the children (left, right) struct node {     int value;     node *left;     node *right;     node(int v):value(v),right(0),left(0){) } Input: root node                2             /    \            5       10           / \     /  \          4   3   8    9                    / \      /  \                 12  6  1   11 The expected result will be:            12       ...

Decoding numeric string to alphabets.

Image
Problem Given a string of integers returns the number of ways to decode integers back to Alphabets using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 examples: input = 199 output = 2 explanation: 1-> 9 -> 9 (AII) 11-> 9 (KI) input = 11 output = 1 explanation: 1->1 (AA) 11 (K)

Finding the shortest path from start to end word given list of words

Given list of array and start and end word as below:    ["hot", "hit", "his", "hat"] Start word: "hot" End word: "his" Find the shortest sequence starting the from start and ending the with end word. The rule is, from the start word, each time you can only change one character, and only use words from the given set, find out how to get to the end word. In the above example, the sequence is:    hot  -> hit -> his (hat is not used) for this example: start = 'his' end = 'hit' input = ["his", "has", "hit", "hat"] we can find this: his -> has -> hat -> hit. However: his -> hit is the sorted path.

Checking whether interval (a,b) is covered given 1-D list of coordinates

Question Given 1-D list of co-ordinates determine if interval (a,b) is covered Ex - [(2,5), (5,7),(1,4)] and interval = (1,6) return true Explanation - Points 1 to 6 lies in list of interval given 1 to 4. 2 to 5 and 5 to 7. [(1,4),(6,7),(2,5)] and interval - (1,6) return false Explanation - Distance between 5 to 6 is not covered in the list given so return false

Power of 3 problem

Problem Write function to determine if given unsigned 32-bit number is a power of 3     int is_power_of_3(uint32_t n)

Design the BigString class

Problem [Revised] Design the BigString class which has the following public methods // method to add char to the word at the specified index. void insert (char c, int pos) {   // } //method to return the word at the specified index. word * search(int index) { // } Example) insert('a', 0); ==> [a] insert('b', 0); ==> [ba] insert(' ', 0); ==> [ ba] insert('c', 0); ==> [c ba] insert('e', 11) ==> [c ba       e] insert('f', 8); ==> [c ba    f   e] insert('o', 3)  ==> [c boa    f   e] insert('u', 10) ==> [c boa    fu   e] search(0) ==>  c search(1) ==>  boa search(2) ==>  fu search(3) ==>  e

Write serialize and deserialize functions for an array of strings

Problem Write 2 functions to serialize and deserialize an array of strings. strings can contain any Unicode character. Do not worry about string overflow. input = ['abdcd', '4agasd-dsfafdas', 'hi there I love you'] output = serialize(input) deserialize(output) = ['abdcd', '4agasd-dsfafdas', 'hi there I love you']

Finding the shortest sequence containing the keywords (Minimum window subsequence problem)

Problem Find the shortest string [] containing the keyword inside Example, Words: sky cloud google search sky work blue Keywords: sky blue Return: sky work blue