Skip to main content

Posts

Showing posts with the label MakemyTrip

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

Height of a Tree [EASY/IMPORTANT]

Company: MakeMyTrip, FreeCharge, FactSet, CouponDunia, Cadence, Amazon, VMWare, Teradata, Synopsys, Snapdeal, Monotype The height of a binary tree is the number of edges between the tree's root and its furthest leaf. This means that a tree containing a single node has a height of  . Complete the  getHeight  function provided in your editor so that it returns the height of a binary tree. This function has a parameter,  , which is a pointer to the root node of a binary tree.  Note  -The Height of binary tree with single node is taken as zero. Input Format You do not need to read any input from stdin. Our grader will pass the root node of a binary tree to your  getHeight function. Output Format Your function should return a single integer denoting the height of the binary tree. Sample Input Note:  A  binary search tree  is a binary tree in which the value of each parent node's left child is les...

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

Longest Prefix Suffix [MEDIUM]

Company: MakeMyTrip, Amazon, Accolite Question: Given a string of character, find the length of longest proper prefix which is also a proper suffix. Example: S = abab lps is 2 because, ab.. is prefix and ..ab is also a suffix. Input: First line is T number of test cases. 1<=T<=100. Each test case has one line denoting the string of length less than 100000. Expected time compexity is  O(N) . Output: Print length of longest proper prefix which is also a proper suffix. Example: Input: 2 abab aaaa Output: 2 3 CODE: import java.util.*; import java.lang.*; import java.io.*; class Solution{ public static void main (String[] args) { Scanner sc = new Scanner (System.in); int m = sc.nextInt(); for(int mi=0;mi<m;mi++){    String s= sc.next();    int i=0, max=0;         for (int j=1;j<s.length();j++){         {if (s.charAt(i)== s.charAt(j))        ...