Posts

Showing posts from August, 2019

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            /       \         5         11        /    \      /    \     4     3  10        9                 /   \       /   \             8    6    1      2