Top companies like Google, Microsoft, frequent a lot of problems in interviews. The basic research will yield a lot of results, but we went a step further to pull out the most common problems. Knowledge of these problems will definitely give you an edge over your competitors in interviews.
Profit Maximization :
First line contains number of test cases ‘T’. Each test case contains the integer value ‘N’, denoting the number of days followed by an array of oil barrel prices in N days.
The days on which the barrels should be bought and sold to maximize profit should be displayed as shown below. And if there is no possibility to make profit then print -1. Multiple deals have to be included in the same line. One cannot buy more than one barrels of oil at the same time. Meaning you have to sell the barrel before buying again.
130 190 230 310 40 285 565 645
34 16 24 28 38 17 31 46 62 69
79 65 34 29 29 24 19
(0 3) (4 7)
(1 4) (5 9)
Given a string of length N reverse the order of words in it. Words are separated by dots.
The first line contains ‘T’, denoting the number of testcases. This is followed by individual test cases. Each case contains a string made up of spaces and characters.
For each test case, output a single line containing the string with the reversed words.
Given a binary tree, find if it is height balanced or not. A tree is height balanced if the difference between heights of left and right subtrees is not more than one for all nodes of tree. Expected time complexity is O(n).
A height balanced tree
An unbalanced tree
The task is to complete the method which takes one argument, root of Binary Tree. The following characters use the mentioned format:
N M (L/R) , N mentions the root for the node M, L/R defines whether the element M is part of the left subtree or right subtree.
There are multiple test cases. For each test case, this method will be called.
The function should return true if tree is height balanced, else false.
1 2 L 2 3 L
10 20 L 10 30 R 20 40 L 20 60 R
Number of Cities:
A group of connected 1s forms a City now your task is to complete the method findCity which returns the no of Cities present. The function takes three arguments. The first is the boolean matrix A and then the next two arguments are N and M denoting the size of the matrix A .
The first line of input will be the no of test cases T. Then T test cases follow. The first line of each test case contains two space separated integers N and M. Then in the next line are the NxM inputs of the matrix A separated by a space.
The expected output will be the total no of cities present.
1 1 0 0 0 1 1 0 1
There are a lot of other questions that are frequented by many companies. While there is no way to know which problems you will be asked, it is best to remain prepared. This is a small list of questions, but you can search for the most commonly asked questions to improve your prep.
We will be releasing the solution in a week’s time so that you can have time to work on the problem from your end.
For other more interesting and challenging problems, log on to Xobin(https://xobin.com ) and interact with the bot.