Problem Solving Interview Questions
- 7of 7 votes
AnswerGiven a text file - find out all the unique words and display the frequency of each word in descending order.
- Ankit May 31, 2021 in India| Report Duplicate | Flag | PURGE
Kasheruka SDE-2 Problem Solving - 1of 1 vote
AnswersGiven a input string 'Hello World' and a input reference String, give count of each character (from refString) in the given string
- Ankit May 31, 2021 in India
Eg inputString: "Hello World Please", refString: "Help"
Output: H: 1, e: 3, l: 4, p: 1| Report Duplicate | Flag | PURGE
Kasheruka SDE-2 Problem Solving - 0of 0 votes
Answerstext = 'ABCDEFGHIJ'
- allen zhao August 24, 2020 in United States
output = '"A""| Report Duplicate | Flag | PURGE
Two Sigma Software Engineer Problem Solving - -1of 1 vote
AnswersYou are given a series of arithmetic equations as a string, such as:
- Manoj May 26, 2020 in India
y = x + 1
5 = x + 3
10 = z + y + 2
The equations use addition only and are separated by newlines. Return a mapping of all variables to their values. If it's not possible, then return null. In this example, you should return:
{
x: 2,
y: 3,
z: 5
}| Report Duplicate | Flag | PURGE
Google Software Engineer Problem Solving - 0of 0 votes
AnswersProblem:
- giridharikhandelwal1 January 03, 2020 in India
1. Given a Mix of all types of characters which includes Special characters, Numbers, String in a Log file.
for eg: "HappyI%&&87Christmas %%$^%&NewYear"
2. Get the largest substring which
"contains the Characters in Even Position followed by a Special Character and
then a meaningful word should be coming up"| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Problem Solving - 1of 1 vote
AnswersGiven multiple tuples in the form of (A,B) where A is the parent and B is the child in a binary tree, find if the input is valid or not. 4 error conditions were provided:
- Ankita October 14, 2018 in United States
1. If a parent has more than 2 children,
2. If duplicate tuples entered,
3. If the tree has a cycle,
4. If more than one root possible.
For violation of multiple validity conditions, print the condition coming first in the above order.
If the input is valid, print the tree in a serial representation. For eg: If input is (A,B), (B,C), (A,D), (C,E) , output: (A(B(C(E)))(D))| Report Duplicate | Flag | PURGE
Starup SDE-2 Algorithm Problem Solving - 0of 0 votes
AnswerYou are using a Webmail UI like GMail. You have to send a "Hello" mail to a person.
- TurboMap June 22, 2018 in United States
1. Write all the scenarios which you would cover in an automated test framework.
2. If you have to test it for 50 different users, what are the challenges you might face in writing your test scripts?
It seems like a pretty easy solution. But at the end he said I need to answer based on the amount of experience I have. I have 9 years of experience as a QA. And he wanted me to give a solution like I actually have 9 years of experience. In short, I blew this question.| Report Duplicate | Flag | PURGE
PayPal Quality Assurance Engineer Problem Solving - 0of 0 votes
AnswersGiven a wall, which is made up of two types of bricks (Porus / opaque ). Porus bricks allow water pass through them. Opaque won't. Find whether water reaches to ground, if there is any rainfall.
- gopi.komanduri June 11, 2018 in India for Office
Water can flow from top to bottom, diagonally, horizontally as well. Only flowing from bottom to top is not possible.| Report Duplicate | Flag | PURGE
Microsoft SDE-3 Algorithm Arrays Brain Storming Coding Data Structures Dynamic Programming Problem Solving Programming Skills - 0of 0 votes
AnswersGiven a string S(a data structure) that contains only square brackets, convert it to an array that stores arrays in the following format: [positionOpeningBracket, positionClosingBracket, nestedDataStructure]. Example: https://i.imgur.com/vZhlZdr.png
- lopogax October 29, 2017 in United Statesdef parser(S): #whatever... print(r) parser("[[]][]") #output: [[0,3,[1,2,null]], [4, 5, null]]
| Report Duplicate | Flag | PURGE
unknown Software Engineer Problem Solving - 0of 0 votes
AnswersGiven that :
- its007Kevin October 20, 2017 in Canada
A -> 1
B -> 2
…
Z -> 26
AA -> 27
AB -> 28
…
BA -> 53
Write a function that returns the value given a string of uppercase letters.| Report Duplicate | Flag | PURGE
OLAP Vision Intern Problem Solving - 0of 0 votes
AnswersYou are given a tree and any of the leaf node which is given as input is set to fire. And in each unit time all the neighbouring nodes of the nodes which are already in fire also catch fire. Given a tree find the time taken for the whole tree to catch fire.
- manikadanmanio October 10, 2017 in United States
The whole catches fire meaning all nodes catches fire.
Example :
4
/ \
5 6
/ \ / \
7 8 9 10
\ \
13 11
\
12
Assume the source leaf node : 9
At 1 sec : 6 catches fire
At 2 sec : 10 and 4 catches fire
At 3 sec : 5 catches fire
At 4 sec : 7 and 8 catches fire
At 5 sec : 13 and 11 catches fire
At 6 sec : 12 catches fire
If we have access to parent pointers its easy just BFS and keeping track of visited we get the answer.
How to go about the problem if we do not have access to parent pointers ??| Report Duplicate | Flag | PURGE
unknown Software Engineer / Developer Problem Solving - 0of 0 votes
AnswersYou are given a Log that contains UserId, ProcessId, Start Time, End Time and Resource Consumption during that time, you need to find out the user who has utilized the most resources.
Example:UID PID StartTime EndTime Consumption
1 1 200 300 100
2 2 230 340 80
1 3 245 315 50
1 4 305 330 20
Time 200 signifies: 02:00.
- CodeNinja September 10, 2017 in United States for AWS
Output: UID# 1
UserID 1 because he has consumed the most number of resources between 200 to 315 (Resource Consumption: 150).| Report Duplicate | Flag | PURGE
Amazon SDE-2 Hash Table Problem Solving - 0of 0 votes
AnswersYou are given a set of N horizontal lines which are connected by equal number of vertical lines to form squares of size 1x1. Now some segments are removed. You need to count the number of squares of all sizes (1x1, 2x2, ..., NxN) with all sides present.
- imunique August 30, 2017 in India
Image : https://he-s3.s3.amazonaws.com/media/uploads/1ce3516.png
In the above example you see four horizontal and vertical lines and few missing segments. Now you need to count the number of squares of all sizes with all sides.
Input :
First line is a positive integer N, number of horizontal and vertical lines.
Second line is positive integer M, number of segments removed.
Then there are m lines, each containing V,i,j or H,i,j where i and j are positive integers. H,i,j indicates a horizontal missing segment in the ith horizontal line between the jth and (j+1)th point on the line. V,i,j represents a gap in ith vertical line between the jth and (j+1)th point on the line.
Output :
Is the total number of squares in the figure with all sides along the remaining lines in the figure.
Sample Input :
4
4
H,2,1
H,3,1
V,2,2
V,2,3
Output :
5
Explanation : Here in this figure we have 4 squares of size 1x1 and 1 square of size 3x3, hence total is 5.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm Data Structures Dynamic Programming Online Test Problem Solving - 2of 2 votes
AnswersWe have N gas stations, and we are given all the distances between each pair of station. So we have nC2 distances provided to us. For example if I have 3 stations namely A, B, C the distances provided will be AB, AC, BC. We have to find the exact position of each gas station provided with these nC2 distances.
- logan9 August 05, 2017 in United States
eg. we have 5 stations so 5C2 distances are given in random order - 10, 20, 70, 80, 30, 20, 100, 70, 50, 90
Output the exact positions of gas stations A, B, C, D, E
i.e
A - 0
B - 10
C - 30
D - 80
E - 100
refer this image for more clarity
https://drive.google.com/open?id=0BxPkptdH01OBZzEwX29iRGI4cEU| Report Duplicate | Flag | PURGE
Google Software Engineer Problem Solving - 4of 4 votes
AnswersGiven an integer array which represents the heights of adjacent vertical bars standing on the ground.
- viveksingh.ds April 08, 2017 in India
The width of each bar is 1. Now you have to pick two bars and remove all the remaining such that when
rain falls the water collected between two bars is maximum. Note that the distance between bars
remains the same after removing the remaining bars.
eg:
1. [10,5,6,12,14] ans: 30 (10*3)
2. [3 16 10 5 6 12 20 18] ans: 80 (16*(number of integers between 16 and 18)).| Report Duplicate | Flag | PURGE
Directi Software Developer Problem Solving - 0of 0 votes
Answers
- xankar February 26, 2017 in United Statesimport 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) { //TODO: } }
| Report Duplicate | Flag | PURGE
Opentable Backend Developer Algorithm Data Structures Java Problem Solving - 0of 4 votes
AnswersYou have L, a list containing some digits (0 to 9). Write a function answer(L) which finds the largest number that can be made from some or all of these digits and is divisible by 3. If it is not possible to make such a number, return 0 as the answer. L will contain anywhere from 1 to 9 digits. The same digit may appear multiple times in the list, but each element in the list may only be used once.
- Parth Patel February 21, 2017 in United States
{{
Test cases
==========
Inputs:
(int list) l = [3, 1, 4, 1]
Output:
(int) 4311
Inputs:
(int list) l = [3, 1, 4, 1, 5, 9]
Output:
(int) 94311
}}
My Solution:
{{
package com.google.challenges;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Answer {
public static int answer(int[] l) {
// Your code goes here.
ArrayList<Integer> list0 = new ArrayList<>();
ArrayList<Integer> list1 = new ArrayList<>();
ArrayList<Integer> list2 = new ArrayList<>();
int sum =0;
Arrays.sort(l);
for(int i = 0; i<l.length; i++){
if(l[i] % 3 == 0){
list0.add(l[i]);
}else if(l[i] % 3 == 1){
list1.add(l[i]);
}else{
list2.add(l[i]);
}
sum += l[i];
}
if(sum%3==0){
StringBuilder strNum = new StringBuilder();
for(int i = l.length-1; i >= 0; i--)
{
strNum.append(l[i]);
}
return Integer.parseInt(strNum.toString());
}else if(sum%3 == 1){
if(list1.size()>0){
Collections.sort(list1);
list1.remove(0);
}else if(list2.size() >= 2){
Collections.sort(list2);
list2.remove(1);
list2.remove(0);
}else{
return -1;
}
}else if(sum%3 == 2){
if(list2.size()>0){
Collections.sort(list2);
list2.remove(0);
}else if(list1.size() >= 2){
Collections.sort(list1);
list1.remove(1);
list1.remove(0);
}else{
return -1;
}
}
list0.addAll(list1);
list0.addAll(list2);
StringBuilder strNum = new StringBuilder();
Collections.sort(list0);
for(int i = list0.size()-1; i >= 0; i--)
{
strNum.append(list0.get(i));
}
return strNum.length() > 0 ? Integer.parseInt(strNum.toString()) : -1;
}
}
}}
But here I am able to pass 4 test cases out of 5. Therefore I am looking for scenario which is left to check.
Can someone help me?| Report Duplicate | Flag | PURGE
Google Software Engineer Google FooBar 24x7 Google chrome technical support number 1-888-201-2039 Arrays Computer Science Java Problem Solving - 9of 9 votes
AnswersGiven a random function with equal probability of getting 1 or 0 ie 50% each. write a custom function which uses the above random function such that your function should return 1 with 75% probability and 0 with 25% probability
- coolcoder3 July 22, 2016 in India| Report Duplicate | Flag | PURGE
Oracle Software Developer Algorithm Problem Solving - 0of 0 votes
AnswersA planner wants to deign a city. A city having n points of interest and marked them from 0 - (n-1). Need to write two API:
- Harsh123 June 12, 2016 in India
public void buildRoad(int a, int b); // build road directly between a and b.
public boolean isRoadExist(int a, int b); // Check if there is any road connectivity exist between a & b (either directly or indirectly) then return TRUE else FALSE.
The solution should be in O(log n). You can first try in O(n).| Report Duplicate | Flag | PURGE
Amazon SDE-2 Problem Solving - 0of 2 votes
AnswersWrite all jumbled number which is >0 && <N, where N is provided by the user.
- Harsh123 June 12, 2016 in India
A jumbled number is a number whose neighbour digit (either left or right) max differ by 1 value.
e.g.:
8987 is a jumbled number.
13 is not a jumbled number.
123456 is a jumbled number.
287 is not jumbled number.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Problem Solving - 0of 0 votes
AnswerYou have a guy who is walking on a street with "X" doors on one side
- somnathdutta048 June 04, 2016 in India
(say left side).From the third round, He has to walk "X" rounds to and
fro( from point A, starting point to B, ending point).
So he walks "X" times from A to B, and back "X" times.
First two rounds he just walks to and fro.
Every time he walks he closes the particular doors corresponding to
the number of the round of his walk, starting from the third round. So
at the third round, he closes the third door, sixth door, ninth door,
.... upto
"X", if "X" is a multiple of 3,
"X-1", if "X-1" is a multiple of 3
AND
"X-2", if "X-2" is a multiple of 3
Then he walks till the "X" door. This he does for every round, till
the "Xth" round.
So, if X is 300, he walks upto the 300th door, closes the 300th door
and returns.
If X is 400, he closes upto 399th door, goes till the 400th door and returns.
If X is 500, he closes upto 498th door, goes till the 500th door and returns.
While returning, he just does nothing. He just returns to where he
started i.e. POINT A.
Likewise for the fourth round, where he close doors that are multiples
of 4 i.e. 4, 8, 12, 16, etc till X (Similar calc as in the 3rd round,
except that we consider multiples of 4 here).
And so on till the "Xth" round.
I.E.
This continiues till "X" rounds. So, from 3 to X rounds. Note that we
have not included 1st and 2nd rounds.
Problem here is:
Write the code in any language of your choice to find:
What is the minimum number of the round where he would not have to close any door?| Report Duplicate | Flag | PURGE
Accenture Analyst Problem Solving - 0of 0 votes
AnswersSystem design of high traffic eCommerce website including inventory
- harshsinghx April 14, 2016 in United States| Report Duplicate | Flag | PURGE
Problem Solving - 0of 0 votes
AnswersImplement a solution nth_largest( array, n ) that takes in an array of arbitrary size and returns the nth largest element.
- NS March 03, 2016 in United StatesEg. array = [1, 8, 4, 5, 9, 7, 2, 10, 44, 55, 67] nth_largest( array, 2) = 55 nth_largest( array, 5) = 9
| Report Duplicate | Flag | PURGE
JP Morgan Software Engineer / Developer Problem Solving - 0of 0 votes
AnswersWrite a program to print all permutations of a given string.
- NS March 03, 2016 in United States| Report Duplicate | Flag | PURGE
JP Morgan Software Engineer / Developer Problem Solving - 0of 0 votes
AnswersGiven the X Y coordinates, width and length of 2 rectangles. Implement a function which returns "True" if the 2 rectangles intersect otherwise returns "False". The first 2 values represent the X Y coordinates, the following 2 represent the width and length.The last 4 values represent the second rectangle. The "8" values should be read from console and the result should be printed to console. Test input "1 1 1 1 -1 -1 3 3"
- bajan_coder February 27, 2016 in United States| Report Duplicate | Flag | PURGE
JP Morgan Applications Developer Problem Solving - 0of 0 votes
AnswerA delivery boy wants to deliver some items on his way from office to home. You need to find the optimized path he should take from office to home and deliver all his deliveries on his way.
- mirinda January 09, 2016 in India
It is 101 X 101 grid. Office, home , delivery points are represented via coordinated (x,y) where 0 <= x <= 100, 0 <= y <= 100.
distance between two points (x1, y1) and (x2,y2) is computed as |x1 - x2| + |y1 - y2|
You need to find the optimized path from office to home covering all delivery locations and return the optimized path length as output.
You will be given the input in the 2 lines
first line - N (no. of delivery locations)
second line - (x,y) coordinates of office, followed by home, followed by all N delivery locations.
3
0 0 100 100 20 30 50 50 70 70
output: The length of the optimized path taken.
For above input, the output is 200| Report Duplicate | Flag | PURGE
Samsung Software Developer Problem Solving - 3of 3 votes
AnswersGiven 4 teams and 3 gamedays, create an algorithm such that each team plays another team every gameday and by the end of the 3 game days each team should have played one game with every other team.
- popeye123 January 03, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Algorithm Problem Solving - 0of 0 votes
AnswersHow would you convert a row number on Excel to a label? Rows are labeled alphabetically with letters added on once the alphabet has been fully used. (Ex. row # 5 is labeled E, row # 27 is labeled AA, row # 28 is AB, row # 53 is BA and so forth) What would the row label be for a large number, such as 1500?
- popeye123 January 02, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Problem Solving - 0of 0 votes
AnswersDesign a train system which suggests shortest path and transfer needed to reach from source to destination. What can be the optimization.
- hm September 30, 2015 in United States
For example:
A system may have 10 trains from t1 to t10.
There are total 100 stops in the system s1 to s100.
Each train has fixed set of stops. You could allow to change and transfer train of source and destination does not cover using just 1 train.
What all can be APIs, data structure, optimizations scalable option.| Report Duplicate | Flag | PURGE
Software Engineer Algorithm Problem Solving Software Design System Design Trees and Graphs design - 0of 0 votes
AnswerYou are planning a big programming conference and have received many proposals which have passed the initial screen process but you're having trouble fitting them into the time constraints of the day -- there are so many possibilities! So you write a program to do it for you.
- Rahul July 07, 2015 in India
The conference has multiple tracks each of which has a morning and afternoon session.
Each session contains multiple talks.
Morning sessions begin at 9am and must finish by 12 noon, for lunch.
Afternoon sessions begin at 1pm and must finish in time for the networking event.
The networking event can start no earlier than 4:00 and no later than 5:00.
No talk title has numbers in it.
All talk lengths are either in minutes (not hours) or lightning (5 minutes).
Presenters will be very punctual; there needs to be no gap between sessions.
Note that depending on how you choose to complete this problem, your solution may give a different ordering or combination of talks into tracks. This is acceptable; you don’t need to exactly duplicate the sample output given here.
Test input:
Writing Fast Tests Against Enterprise Rails 60min
Overdoing it in Python 45min
Lua for the Masses 30min
Ruby Errors from Mismatched Gem Versions 45min
Common Ruby Errors 45min
Rails for Python Developers lightning
Communicating Over Distance 60min
Accounting-Driven Development 45min
Woah 30min
Sit Down and Write 30min
Pair Programming vs Noise 45min
Rails Magic 60min
Ruby on Rails: Why We Should Move On 60min
Clojure Ate Scala (on my project) 45min
Programming in the Boondocks of Seattle 30min
Ruby vs. Clojure for Back-End Development 30min
Ruby on Rails Legacy App Maintenance 60min
A World Without HackerNews 30min
User Interface CSS in Rails Apps 30min
Test output:
Track 1:
09:00AM Writing Fast Tests Against Enterprise Rails 60min
10:00AM Overdoing it in Python 45min
10:45AM Lua for the Masses 30min
11:15AM Ruby Errors from Mismatched Gem Versions 45min
12:00PM Lunch
01:00PM Ruby on Rails: Why We Should Move On 60min
02:00PM Common Ruby Errors 45min
02:45PM Pair Programming vs Noise 45min
03:30PM Programming in the Boondocks of Seattle 30min
04:00PM Ruby vs. Clojure for Back-End Development 30min
04:30PM User Interface CSS in Rails Apps 30min
05:00PM Networking Event
Track 2:
09:00AM Communicating Over Distance 60min
10:00AM Rails Magic 60min
11:00AM Woah 30min
11:30AM Sit Down and Write 30min
12:00PM Lunch
01:00PM Accounting-Driven Development 45min
01:45PM Clojure Ate Scala (on my project) 45min
02:30PM A World Without HackerNews 30min
03:00PM Ruby on Rails Legacy App Maintenance 60min
04:00PM Rails for Python Developers lightning
05:00PM Networking Event| Report Duplicate | Flag | PURGE
Amazon SDE-2 Problem Solving