Recent Interview Questions
 0of 0 votes
Optimization Game
Currently, Monk is playing a unique kind of strategy game called optimisation game.
In this game we are provided with an array containing integral numbers.
Now all these numbers represent the count of their respective index power of 2.
The goal of the game is to minimize the total sum of the count of the array by converting lower powers of 2 into their higher powers
i.e. for example (2)*2^1 = (1)*2^2.
Note that we can extend the array beyond the final index i.e. N−1 too in case it optimizes our result.
Please see the below example for more understanding.
Let the number of elements given in the initial array be 3. Consider the array to be [1,2,0].
It means that 2^0 has count = 1, 2^1 has count = 2, 2^2 has count = 0.
Now, we can convert (2)*2^1 into (1)*2^2 as 2^1∗2 = 2^2. We get the new array as [1,0,1].
Now the total sum is 1+0+1=2 which is the required minimum value obtained at the end of the game as we can't reduce it any further.
Input:
First line will contain the number of test cases as T.
For each of the test case, N will be given in the first line and N integers will be given in the second line.
Output:
Output the minimum value obtained after playing the optimization game in a separate line for each test case.
Constraint:
1≤T≤5
1≤N≤10^5
0≤A[i]≤2∗10^9
Sample Input
2
3
1 2 1
2
2 1
Sample Output
2
1
Explanation
In the second case we have A[0]=2, A[1]=1. We can convert A[0] into A[1] and then finally (1+1=2) A[1] into A[2]. Thus, the final array shall be : [0,0,1]. Hence, the answer is 1.
 0of 0 votes
On google search, how to enable key word auto completion after a few letters typed.
Followup: How to rank the words if they are weighted by frequency?
 1of 1 vote
Cross the street
ABC Company is involved in the logistics business.
The company has many outlets and stockyards in a city. The city is like an
N
×
M
N×M grid. We consider a single cell of the given grid to be a single block in the city. The stockyard is at the upperleft corner and the outlet is located in the lower right corner. Everyday, one of the employees has to travel from the upper left to the lower right corner for supplies. Each block in the city has a height, where the height of the block located at position (i,j) in the grid is equal to
A
[
i
]
[
j
]
A[i][j]. The company wants to change the heights of some of the blocks, so that the employee can enjoy a highspeed drive from the stockyard to the outlet. But this change comes at a certain cost.
Specifically, if they change a block height from x to y, then they must pay exactly

x
−
y

x−y dollars. Please help them find the minimum cost, such that by spending that specific amount, they can get a path from stockyard to the outlet with all blocks along the path having the same height.
In a single move, the employee can move from a block to any of its adjacent blocks. Note that during this journey, the employee is allowed to move in all four directions, fulfilling the condition that he never goes out of the grid at any point in time.
Input :
First line contains two positive integers N and M  number of rows and columns in the city. Then, N lines follow, each containing M integers, where the
j
t
h
jth integer on the
i
t
h
ith line denotes
A
[
i
]
[
j
]
A[i][j].
Output :
The first and only line of output should contain minimum cost.
Constraints :
1<= N, M <=100
1<= height of blocks <=100
Sample Input
5 5
1 1 1 1 1
9 9 9 9 1
1 3 3 3 1
1 9 9 9 9
1 1 1 1 1
Sample Output
6
Explanation
Optimal path taken by the employee will be : (1,1) > (1,2) > (1,3) > (1,4) > (1,5) > (2,5) > (3,5) > (3,4) > (3,3) > (3,2) > (3,1) > (4,1) > (5,1) > (5,2) > (5,3) > (5,4) > (5,5) The height of each block along this path can be changed to
1
1, at a total cost of
6
6. There is no way to get a cost less than this.
 0of 0 votes
Alex has recently decided to learn about how to design compilers. As a first step he needs to find the number of different variables that are present in the given code.
So Alex will be provided N statements each of which will be terminated by a semicolon(;). Now Alex needs to find the number of different variable names that are being present in the given statement. Any string which is present before the assignment operator denotes to a variable name.
Input Format: :
The first line contains a single integer N
Each of the next N lines contains a single statement.
It is guaranteed that all the given statements shall be provided in a valid manner according to the format specified.
Output Format: :
Print the number of different variable name that are present in the given statements.
Sample Input
2
foo = 3;
bar = 4;
Sample Output
2
Explanation
Foo and Bar are only two variables used inside the statements so answer is 2.
 0of 0 votes
Design classes to represent the following problem and solve the questions 1,2,3
A user might have some outstanding auto loan amount and you have 3 types of offers: personal loan, credit card and auto loan offers. You need to provide the user
with the following details:
1. Send user all the offers to the user
2. Send user all eligible offers (where minCreditScore < userCreditScore < maxCreditScore)
3. Send user all offers which satisfied 2) and where the (userOutStandingLoanAmount < maxOfferedAutoLoanAmount)
personalloan = [{
"personalloan": {
"id": 1,
"provider": "Avant",
"term": 36,
"minimumCreditScore": 300,
"maximumCreditScore": 700,
"maximumAmount": 10000
}
}, {
"personalloan": {
"id": 2,
"provider": "Prosper",
"term": 24,
"minimumCreditScore": 600,
"maximumCreditScore": 700,
"maximumAmount": 5000
}
}]
creditcard=[{
"creditcard": {
"id": 2,
"provider": "CapitalOne",
"minimumCreditScore": 600,
"maximumCreditScore": 700
}
}, {
"creditcard": {
"id": 3,
"provider": "Chase",
"minimumCreditScore": 300,
"maximumCreditScore": 900
}
}]
autoloan = [{
"autoloan": {
"id": 1,
"provider": "CapitalOne",
"term": 36,
"minimumCreditScore": 300,
"maximumCreditScore": 700,
"maximumAmount": 10000
}
}, {
"autoloan": {
"id": 2,
"provider": "Blue Harbor",
"term": 24,
"minimumCreditScore": 600,
"maximumCreditScore": 700,
"maximumAmount": 5000
}
}]
 0of 0 votes
This is a twopart question.
Part one: Design one or more classes to represent the intersections and streets
in a city. Streets can be either oneway or twoway.
Part two: Using the classes from the previous question, determine whether there is a pair of intersections (A,B) such that there is exactly one route from A to B.
 0of 0 votes
1) Finish writing the below method: bookReservation(Reservation reservation)
2) You are free to add, modify, etc the following classes and methodimport java.time.Duration; import java.time.LocalTime; import java.util.List; import java.util.Map; // Your goal is to write business logic for a very simple Restaurant booking system // You are encouraged to refactor exisiting code, create other classes, write helper methods etc // You also need to make sure that the implementation works correctly class Reservation { public String name; public int partySize; public LocalTime startTime; } class Table { public int tableNumber; public int maxPartySize; } class Restaurant { public List<Table> tables; public LocalTime openTime; public LocalTime closeTime; public Map<Integer, Duration> reservationDurationsPerPartySize; // Returns a Table if Reservation could be booked, null otherwise // Booking rules: // 1) Reservation could be made only when the Restaurant is open. // 2) Only one Reservation can be seatted a Table at any time. // 3) Reservation can be seatted only at a Table of the same or a bigger size. // 4) Reservation should stay on the same Table for the whole Duration. // 5) Reservation Duration is determined by PartySize. public Table bookReservation(Reservation reservation) { //fill this method }
 0of 0 votes
I need to create a database that have five columns each entry is such that there can be repeated tuples in each column(No primary key).There will be no two same entries
There are 5 Methods that needs to be implemented
1. Create()  create the database
2. Add(string a,b,c,d,e)  Add single entries with 5 tuples(all strings)
3. Update (culumntype1, columnvalue1,culumntype2, columnvalue2)
 each entry having culumntype1 = columnvalue1 will be updated by columntype2=columnvalue2 and return total such eantries.
4. Delete (culumntype1, columnvalue1)
 each entry having culumntype1 = columnvalue1 will be deleted.and return total such eantries.
5. Search(culumntype1, columnvalue1)
 Search each entry having culumntype1 = columnvalue1 and return total such eantries.
How to implement in best possible way such that there can be 50,000 such entries?
 0of 0 votes
Design a system for implementation of stock market.
Buyer and seller case. stock server will receive buy request and sell request. A sell can be successful when it matches the quantity and price for same stock.
There will be many request for buyer and seller . Need to select the appropriate one.
Which data structure will be used ? how to handle concurrency issue?class diagram?
 0of 0 votes
Given an array arr and a number n, you have to find whether there exist a subset in arr whose sum is n. You have to print length of the subset.
1. There exists only one subset like that
2. All number in arr are positive
 1of 1 vote
Consider that the driver with one trip want to pick up some peoples in different locations like this:
String[] locations ={
"person1, person2, person3, person4, person5",
" person6, person7, person8, person9",
"person10, person11, person12",
"person13, person14, person15",}
in each location there are different choice, so write a code present all possible way to pick up people in the different locations. you can use every data structure needs.
 0of 2 votes
i want code of movie recommendation system using knn in java,python,c
 1of 1 vote
Find largest subarray?
 1of 1 vote
given preorder traversal [5,3,2,4,8,7,9] of a BST, how do we identify the leaf nodes without building the tree ?
@Anonymous Thanks for the reply!
Please try other use cases like, only single leaf node
 1of 1 vote
Java:
GENERAL INSTRUCTIONS: To get the half of the word that was inputted by the user, use division to divide into two and use substring method to specify its beginning and ending index.
OUTPUT FORMAT:
The output will be:
* First half of the entered word
* Last 2 letters (from the end)
* Second half of the entered word
 1of 1 vote
You have two servers. Both of these servers have an identical file with billion characters except for one single character. These servers are connected over a very slow connection.
How do you find the different character?
My ans: split those files in to batches of characters of 10,000 (say), now calculate checksum and compare the checksums for the chunks of 10,000 character lines. So now you are just comparing 'ints' and not the files per say. (remember the connection is very slow)
His question: How do you optimize this?
 0of 0 votes
Write a Code
Steve is going to throw a party at his place tonight.He needs to visit two shops near his homethe first shop is d1 meters away from his place,the second shop is d2 meters away from his place, and there are d3 meters between these two shops.Calculate the minimum distance he needs to walk to visit both both shops and return back home. Steve always start from his palce.He can only travel using these 3 routes.HE can use any route any amount of time necessary,the only thing he needs to achieve is the minimum distance.
Find the minimum distance Steve has to walk to visit both shops and return home.
input: 1,1,1
output: 4
input: 10,20,30
output: 60
 1of 1 vote
Google Chrome Technical support number: Google chrome is one of the prime assets to open any website very smoothly. Many a times, it betrayed to various clients as it shows difficulty to open the particular website. Due to some technical hindrance, some person has to face cracking issue and fixing this issue is not under the control of other person. So, it is advised that you should have to end your query at our third party destination because we have perfect knowledge to chase the problem in the appropriate manner. Our professional will help to you as you dial Google Chrome Technical support number speak out all problems at our toll free number. To know more information, you have to browse our web portal:
http://www.emailhelpnumber.com/googlechromesupport.html
 1of 1 vote
Gmail Technical support number: Maximum personality advocated making smooth communication to save your phone bill. Hence, they are addicted into in built chatting service and incredible Gmail tech support. Even through filling the accurate credential details in the form of the user name and password, establishing the user friendly communication without the error message and prompt is not easy task. If you are getting difficulty to access your account to enjoy all cheered function, then you should have to get assistance of expert through dialing Gmail technical support phone number +448000903909. Otherwise, you will have to bear several losses in the Gmail account. Our team is offering support at nominal price value. At the peak of urgency, you should have to dial our toll free number.
for more info visithttp://www.customeremailsupportnumber.com/gmailsupport.html
 1of 1 vote
Yahoo mail not receiving emails
If you facing issues related with your email, it may be that there would be some severe issues with your Yahoo account. So, here you need have the proper diagnosis of your Yahoo account so that you could know about the actual issue that is running with your Yahoo account. Here, without thinking anything you should dial a Yahoo technical support number. With Yahoo technical support number you can easily find solution of your choice. So, just dial a Yahoo technical support number and find the solution at the very fast and reasonable rate.
http://www.emailsupportdesk.com/yahoocustomercare.html
 1of 1 vote
Given estimated stock quotes, in an array, print the maximum profit from a buy and sell. i.e [19, 22, 15, 35, 40, 10, 20] would show a profit of 25(40 15). The sale must come after the buy. Solve this in O(N) time.
<?php function print_max_profit($arr){ if(count($arr) < 1) return 0; $len = sizeof($arr); $profit = 0; $least = $arr[0]; for($i = 0; $i < $len; $i++){ $least = min($least,$arr[$i]); $profit = max($profit, $arr[$i]  $least); } return $profit; }
 0of 0 votes
Find the longest cycle in a graph ?
 0of 0 votes
Cross the River
Saatwik, an elite programmer love the woods. Once he was in one of his trips to the mighty Himalayas , he encountered a strange problem. As we all know that, Himalayas has abundant river streams and forests. While travelling in one of the forest, he was trapped by the river stream flowing. As the stream flow was fast, he couldn't cross by swimming across water, he must find some other way to cross it.
River is present throughout the X axis and its boundary is marked by y coordinates (i.e. from y=A to y=B) .
 (y=A)
..................................................................................................
..................................................................................................
..................................................................................................
 (y=B)
Now, You are provided with some rocks along with their centres and radius respectively. Currently Saatwik is present on the shore having y=B . We can't jump between the rocks but we can move from one rock to other if both overlap at some points. You need to tell whether Saatwik will be able to cross the river by using any number of rocks or not . If he can, then output the minimum number of rocks taken to achieve it otherwise output −1
Input :
First line of input will contain T denoting number of test cases. For each of the test cases, First line will contain N denoting number of rocks. From second line onward, there will be N lines containing 3 integers X,Y,R where (X,Y) denotes the coordinates of the centre of that rocks and R stands for its radius. Last line will contain two integers A and B denoting the upper and lower boundary of the river respectively.
Output:
Output the required answer in a separate line for each of the test case.
Constraints :
1≤T≤10
1≤N≤5000
−109≤X,Y,A,B≤109
1≤R≤109
B<A
Sample Input
1
3
1 1 2
1 2 1
3 4 1
3 0
Sample Output
1
Explanation
At first we can step onto the first rock from the river shore. Then we can cross river directly or can move to second rock and then cross it. Note that we can't use third rock as it is beyond the reach from the other rocks.
Time Limit: 2.0 sec(s) for each input file
Memory Limit: 256 MB
Source Limit: 1024 KB
 0of 0 votes
Given an array A of size N, where the ith integer of the array is A[i] and has a value ranging between 1 and 1000 inclusive, you need to help Monk with the following task :
Given 3 additional numbers K, X and Y, you need to report the number of unordered pairs of elements (i,j) from this array, such that (1≤i<j≤N), (A[i]+A[j])%K=X, and (A[i]×A[j])%K=Y.
Input Format :
The first line contains 4 space separated integers N, K and X and Y. The next line contains N space separated integers where the ith integer denotes A[i].
Output Format :
Print the required number of ordered pairs of array elements on a single line. As the answer could be rather large, beware of integer overflows.
Constraints :
2 ≤ N ≤ 10 raised to power 5
1 ≤ K ≤ 10 raised to power 6
0 ≤ X, Y < K
1≤A[i]≤1000
Sample Input
5 2 1 0
1 2 3 2 1
Sample Output
6
 0of 0 votes
how to create an object on the stack.
and also make sure that only 5 objects are created for the class
 1of 1 vote
Given a set of possibly overlapping rectangles in different levels (All of which are "not rotated", can be uniformly represented as (leftbottom,righttop) tuplets), return a minimal set of (nonrotated) nonoverlapping rectangles, that occupy the same area.
The rectangle at lower level has more priority than at higher levels.
 0of 0 votes
There is dedicated Samsung software for coding test the question is given below:
There is one spaceship. X and Y coodinate of source of spaceship and destination spaceship is given. There are N number of warmholes each warmhole has 5 values.
First 2 values are starting coordinate of warmhole and after that value no. 3 and 4 represents ending coordinate of warmhole and last 5th value is represents cost to pass through this warmhole. Now these warmholes are bidirection.
Now the to go from (x1,y1) to (x2,y2) is abs(x1x2)+abs(y1y2).
The main problem here is to find minimum distance to reach spaceship from source to destination coordinate using any number of warmhole. It is ok if you wont use any warmhole.
 3of 3 votes
Getting problem in yahoo mail what to do
If you are finding trouble in accessing your Yahoo mail, it may be that there would be some severe issues running with your Yahoo account. So, here you can connect with an independent service provider of Yahoo. This party service provider services are available throughout day and night. So, their experts are going to make you have prompt solution for Yahoo email issues. Yahoo technical support number helps you to connect directly with an advanced technical expert who can deal with any of the issues with your Yahoo. They are not only going to resolve password issues but also going to strengthen the security of your Yahoo mail.
http://www.emailsupportdesk.com/yahoocustomercare.html
 0of 0 votes
list1 >aaa,bbb,ddd,xyxz,...
list2>bbb,ccc,ccc,hkp,..
list3> ddd,eee,,ffff,lmn,..
Inside a list the words are sorted
I want to remove words which are repeated across the list and print in sorted order
If the words are repeated in same list its valid.
In the above case
it should print aaa>ccc>ccc>eee>fff>glk>hkp>lmn>xyxz
 0of 0 votes
Write a program to compress a string and send it a over a network and decompress it on the receivers end