Skip to main content

Posts

Showing posts with the label Walmart-Labs

LRU Cache [HARD]

Company: Hike, Google, Goldman-Sachs, Flipkart, Expedia, Amazon, Adobe, Walmart-Labs, Ola-Cabs, Microsoft, MakeMyTrip, Intuit, Informatica, Yahoo. Question: The task is to design and implement methods of an  LRU cache . The class has two methods get and set which are defined as follows. get(x)   : Gets the value of the key x if the key exists in the cache otherwise returns -1 set(x,y) : inserts the value if the key x is not already present. If the cache reaches its capacity it should invalidate the least recently used item before inserting the new item. In the constructor of the class the size of the cache should be intitialized.   Input: The first line of input contain an integer T denoting the no of test cases. Then T test case follow. Each test case contains 3 lines. The first line of input contains an integer N denoting the capacity of the cache and then in the next line is an integer Q denoting the no of queries Then Q queries follow. A Query...

Check for BST [MEDIUM]

Company: MakeMyTrip, GreyOrange, Boomerang, Amazon, Adobe, Accolite, Walmart-Labs, VMWare, Snapdeal, Qualcomm, OYO Rooms, Microsoft, Wooker. Question:  Given a binary tree, return true if it is  BST , else false. For example, the following tree is not BST, because 11 is in left subtree of 10.         10      /     \    7       39      \       11 Input: The task is to complete the method which takes one argument, root of Binary Tree. The struct Node has a data part which stores the data, pointer to left child and pointer to right child. There are multiple test cases. For each test case, this method will be called individually. Output: The function should return 1 if BST else return 0. Constraints: 1 <=T<= 30 1 <= Number of nodes<= 100 1 <= Data of a node<= 1000 Example: Input: 2 2 1 2 R 1 3 L 4 10 20 L 10 30 R 2...

Implement Queue using Stack [EASY/IMPORTANT]

Company:Flipkart, De-Shaw, Amazon, Adobe, Accolite, Inmobi, Microsoft, MAQ-Software, MakeMyTrip, InfoEdge, Goldman-Sachs, Walmart-Labs, Oracle Question: Implement a Queue using 2 stacks  s1  and  s2  . Input  : The first line of the input contains an integer ' T ' denoting the number of test cases. Then T test cases follow. First line of each test case contains an integer  Q  denoting the number of queries .  A Query  Q  is of 2 Types (i)  1 x   (a query of this type means  pushing  'x'  into the queue) (ii)  2     (a query of this type means to pop element from queue and print the poped element) The second line of each test case contains  Q  queries seperated by space. Output: The output for each test case will  be space separated integers having  -1  if the queue is empty else the element poped out from the queue .  You are...