## Recent Interview Questions

- 0of 0 votes

AnswersWrite a function to compute n^k. (don't forget negative exponents)

- vmayer99 April 30, 2018 in United States| Report Duplicate | Flag | PURGE

Linkedin Software Engineer Algorithm - 0of 0 votes

AnswersPrint (or return) the longest movie title found by successively matching the last and first words in each title, joining to form new titles, given a file containing a list of movie titles.

- gsgy11 April 30, 2018 in United States

For example: 'OF MICE AND MEN' and 'MEN IN BLACK' join to form 'OF MICE AND MEN IN BLACK'.

You could further join 'OF MICE AND MEN IN BLACK' wth 'BLACK MASS' to form 'OF MICE AND MEN IN BLACK MASS'.

The longest title I found (at 143 characters is): WENT TO CONEY ISLAND ON A MISSION FROM GOD BE BACK BY FIVE WIVES THREE SECRETARIES AND ME WITHOUT YOU CANT TAKE IT WITH YOU WERE NEVER LOVELIER| Report Duplicate | Flag | PURGE

Google Software Engineer - 0of 0 votes

AnswersProblem:

- sarunreddy82 April 29, 2018 in United States

Insert + or – sign anywhere between the digits 123456789 in such a way that the expression evaluates to 100. The condition is that the order of the digits must not be changed.

e.g.: 1 + 2 + 3 – 4 + 5 + 6 + 78 + 9 = 100

I have below C solution - Can you please help me to convert to Java. I need this solution in Java.

#include<stdio.h>

#include<conio.h>

int findnumber(int i,int j)

{

int k;

int n;

for(k = 0; k < j; k++)

{

n = i % 3;

i = i / 3;

}

return n;

}

void main()

{

int i, j, k, current, result, operation;

clrscr();

for(i = 0; i < 19683; i++)

{

if(i%3 == 0)

continue;

current = 0;

result = 0;

for(j = 1; j < 10; j++)

{

k = findnumber(i,j);

if(k==0)

{

current = current * 10 + j;

}

else

{

result = result + (operation == 1 ? current : -current);

current = j;

operation = k;

}

}

result = result + (operation == 1 ? current : -current);

if(result == 100)

{

for(j = 1; j < 10; j++)

{

k = findnumber(i,j);

if(k==0)

printf("%d",j);

else

printf("%c%d",k==1?'+':'-',j);

}

printf("\n");

}

}

getch();

}| Report Duplicate | Flag | PURGE

xyz Java - 0of 0 votes

AnswersImagine a horizontal corridor bounded by y = y1 and y = y2 lines on a 2D-plane. There are N sensors with centers (x, y) each of which operates in a range (r) on the plane . So, they cover some circular areas on the plane. See the figure below.

`o | _____o___o__|____________ y = y1 o |OOO __________oo|_____O______ y = y2 O | O _ _ _ _ _ _ | _ _ _ _ _ _ | o O | o O O | | O | |`

The question is whether a path exist from x=-inf to x=+inf via corridor without being detected any radar.

Constraints:

1. You are free to move any direction only if you stay in the corridor.

2. You are free to go through corridor borders.

3. N sensors are given as list of (x, y, r) like [(1, 3, 2), (-1, -3, 4)]. x and y are signed integers. r is a unsigned integer.

4. y1 and y2 are integers.

My solution:

1. Create an intersection graph of N sensors by comparing them each other via Euclidean distance`(x1 - x2)^2 + (y1 - y2)^2 <= (r1 + r2)^2`

2. If there is a path between y=y1 and y=y2 through intersected sensors, there do not exist any path from x=-inf to x=+inf. Otherwise, there do exist a path. So, I used BFS to search such a path.

Worst Case Complexity:

1. O(n^2)

2. O(V + E) = O(n + intersection_count)`Total: O(n^2)`

My Best Case Optimization for Intersection Graph:

- engineer06 April 29, 2018 in United States

1. For each sensor, create two events for start and end of circles vertically. y = (y1 - r) and y = (y1 + r)

2. For each sensor, register those two events into an array.

3. Use a line sweep algorithm over 2, which is O(nlogn + intersection_count) and intersection_count may be n^2 at worst case.

I wonder if I should have had a better solution with the worst case < O(n^2).| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersNumbers with 4 are considered to be unlucky, floor numbers are skipped with numbers with 4; for a top level n, ask how many layers there are actually; for example n=20, that is 18 levels [Remove 4, 14]

- ajay.raj April 28, 2018 in United States| Report Duplicate | Flag | PURGE

Amazon Java Developer - 0of 0 votes

AnswersLanguage : java

- sarunreddy82 April 27, 2018 in United States

Find the length of the non repeated numbers in an array.

Input : 1,2,2,3,4,5,6,2,3| Report Duplicate | Flag | PURGE

xyz abc Arrays - 0of 0 votes

AnswerYou are given the length and time of occurrence of packet and Queues which process packets. Total processing time for a packet is equal to the length of packet plus the waiting time in queue. For eg lets say we have only one queue for now, and A packet of length 5 comes at t = 1, and another packet of length 4 comes at t = 3. Total processing time for first packet is 5( no waiting time as queue is empty at t = 1) and at t = 3, 2 units of first packet is processed and 3 units remaining so, for second packet 3 units will be waiting time in queue plus 4 units for its length. Total processing time for 2nd packet is 7 units. If there are multiple queues you can add new packet in any of the other queues. Given the time and length of all incoming packets, we need to find the minimum no. of queues required such that total processing time of each packet is less than 10 units. Maximum possible no. of queues are 5. If you require more than 5 queues print -1.

Test Cases Format: First Line contains the number N, the total no. of packets and N following line contains two numbers ti, li where li is length of packet coming at time = ti units.

Test case1:

2

2 7

5 8

Test Case 2:

3

1 3

2 3

3 5

Test Case 3:

3

1 5

2 4

3 8

Output:

Case1: 2

Case2: 1

Case3: 2

Consider the following time table of incoming packets:`time packets-length 1 8 2 5 3 2 4 6`

If you put the packet in queue with minimum time then this will lead to 3 queues:

- ak4017 April 25, 2018 in United States

t = 1:

q1: 8

t = 2:

q1: 7

q2: 5

t = 3:

q1: 6

q2: 4, 2

t = 4:

q1: 5

q2: 3, 2

q3: 6

But its output should be 2 queues:

1) 8 in queue 1

2) 5 in queue 2

3) 2 in queue 1

4) 6 in queue 2| Report Duplicate | Flag | PURGE

Samsung Software Developer Algorithm - 0of 0 votes

AnswersI read this question here in careercup and saw no comments on it. So, I am answering it.

- mohapatrasandeep60 April 24, 2018 in United States

given a string find the sum of number of unique substring characters.

means if string is ACAX. the sub strings are A,C,A,X,AC,CA,AX,ACA,CAX,ACAX. in ACA, A occurs more than once so, its count is not considered, but C occurs once so its count is 1. Similarly in ACAX, A's count=0,C's count=1,X's count=1. In such a manner find sum of all counts for all substrings. The worst case time complexityis O(n). IF same substring occurs more than once then find its sum for that many times.| Report Duplicate | Flag | PURGE

Amazon - 0of 0 votes

AnswerYou are given an array of length N that contains only integer.

- Randhir April 23, 2018 in United States

A number in this array is called a special number if it is divisible by at least one other number in the array.

Write a program to print the count of special number of array.

Input format :

First Line - N

Second line - N space separated integer.

Output format :

print the count of special number in the array.

constraints

1<= N <= pow(10,5)

Note - divisible with same number will not considered.

Example -

input

N=3

Array= 5 3 10

output

1

Description - 10 is divided by 5,

5 and 3 are not divided by any number| Report Duplicate | Flag | PURGE

- 0of 0 votes

AnswersYou are given an array of strings. For example, ["AB", "BC", "FOO", "ZA", "BAZ"]

- thriver April 22, 2018 in United States

- Output strings where you can get from one to the other using any ROT transformation.

ROT_1(AB) = BC

ROT_1(BC) = CD

ROT_25(AB) = ZA

AB,BC you can go from one to the other using ROT_1

Input: list of strings

Output: strings where you can get from one to the other using any ROT transformation.

Example:

Input : ["AB", "BC", "FOO", "ZA", "BAZ"]

Output: [ [ab, bc] , [ab, za] ]

AB,BC because you can go from one to the other using ROT_1

AB,ZA because you can go from one to the other using ROT_25

Do not return FOO, BAZ you can’t get from one to the other.| Report Duplicate | Flag | PURGE

Google Software Developer - 0of 0 votes

AnswersGiven a bar chart which the heights of bars are notated as an array of positive integers. Rectangles can be formed in areas covered by one or more bars. Find the largest rectangle.

- fz April 21, 2018 in United States| Report Duplicate | Flag | PURGE

Software Engineer Algorithm - 0of 0 votes

AnswersHow do you go about the phone interview for troubleshooting a problem, say "my computer has become slow 3 times from the last week.". Can someone please give the detailed explanation of how to go about this question. Also, "my internet is not working". How to go about these 2 troubleshooting problems in the phone interview?

- JayswalShubh April 21, 2018 in Australia| Report Duplicate | Flag | PURGE

Google Technical Support Engineer - 5of 5 votes

AnswersFB On-site March

- aonecoding April 21, 2018 in United States

Q: Find number of Islands.

XXXOO

OOOXX

XXOOX

Return 3 islands.

1 1 1OO

OOO2 2

3 3OO 2

Followup: If the board is too big to fit in memory, how to get the number?| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 0of 0 votes

AnswerGiven two sets of intervals such as {[1, 2], [4, 8]} and {[2, 5]}. Find their union {[1, 8]} for the two intervals.

- fz April 20, 2018 in United States| Report Duplicate | Flag | PURGE

Software Engineer Data Structures - 0of 0 votes

AnswersDesign a dictionary which words are grouped by the same characters. For example, dog and god are in the same group. And how to make it scalable to handle a huge number of words?

- fz April 20, 2018 in United States| Report Duplicate | Flag | PURGE

Software Engineer Data Structures - 0of 0 votes

AnswersGiven an array of elements print even and odd numbers out of it using 2 threads . even_thread and odd_thread.

- anaghakr89 April 19, 2018 in United States

int arr[] = {3,1 ,2, 5, 6, 7, 8, 10, 9};| Report Duplicate | Flag | PURGE

Qualcomm Software Developer - 0of 0 votes

AnswersNeed to design and develop java program for assigning rankings to “Premier League” players. To start with all the players would have zero points. After every game, points would be updated for players based on the performance. Design data structure and algorithm to print the player rankings after every game.

- deepakSU April 18, 2018 in United States

Sample input and outputs:

Input to program would be of the format “player Id, points from the game”. Example :

1 2

2 1

3 5

1 2

2 3

3 5| Report Duplicate | Flag | PURGE

Java - 1of 1 vote

AnswersInterleave list of lists in Java

- npkatre102 April 18, 2018 in United States

Example:

input = [[1,2,3], [9, 0], [5], [-4,-5,-2,-3,-1]];

output = [1,9,5,-4,2,0,-5,3,-2,-3,-1]| Report Duplicate | Flag | PURGE

Facebook Software Developer - 0of 0 votes

AnswersInput unsorted integer array represents a list of coins,

- ajay.raj April 18, 2018 in United States

find the minimum amount of money that cannot be formed by these coins, each coin can only be used once

E.g. {1,1} -> 3, {1,2,4} -> 8| Report Duplicate | Flag | PURGE

Amazon Java Developer - 0of 0 votes

AnswerWe have an array if 0's and 1's like

- johnsvakel April 16, 2018 in India for NA

00010000010001001

Assume that all 1's are a person and if a new person comes and if we want to add to the array in such a way that the gap between individuals are maximum as possible.

if we add a new person, then the new array should be

000100100010001001| Report Duplicate | Flag | PURGE

Microsoft Staff Engineer Data Structures - 0of 0 votes

AnswersGive me a list of int, find the length of the smallest cycle. For example, 1, 2, 1, 2, the length of the cycle is 2. Then 1, 2, 1, 2, 1 has a minimum length of 2. Then the length of 1, 2, 1, 2, 3 should be 5 because the entire list is not in repeat. Then the minimum length of 1, 2, 1, 2, 1, 1, 2 is 2.

- ajay.raj April 16, 2018 in United States| Report Duplicate | Flag | PURGE

Amazon Backend Developer - 0of 0 votes

Answers### Problem 3: Theatre Seating

- harshshukla54 April 15, 2018 in United States

You run a small theater and each month, you have patrons mail in requests for pre-sale tickets. You need to process these ticket requests and either tell them where their party will sit or explain to the patron why you can't complete their order.

You have a few rules that you need to follow when you fill the orders:

1. Fill as many orders as possible

2. Put parties as close to the front as possible.

3. If there are not enough seats available in the theater to handle a party, tell them "Sorry, we can't handle your party."

4. Each party must sit in a single row in a single section. If they won't fit, tell them "Call to split party".

Your program must parse a theater layout and a list of ticket requests and produce a list of tickets or explanations in the same order as the requests.

The theater layout is made up of 1 or more rows. Each row is made up of 1 or more sections separated by a space.

After the theater layout, there is one empty line, followed by 1 or more theater requests. The theater request is made up of a name followed by a space and the number of requested tickets.

Sample input:

```

6 6

3 5 5 3

4 6 6 4

2 8 8 2

6 6

Smith 2

Jones 5

Davis 6

Wilson 100

Johnson 3

Williams 4

Brown 8

Miller 12

```

Your program must produce results to standard output in the same order as the requests, with the name of the person who requested the ticket and either the row and section of the ticket or the explanations "Sorry, we can't handle your party" or "Call to split party."

Sample output:

```

Smith Row 1 Section 1

Jones Row 2 Section 2

Davis Row 1 Section 2

Wilson Sorry, we can't handle your party.

Johnson Row 2 Section 1

Williams Row 1 Section 1

Brown Row 4 Section 2

Miller Call to split party.| Report Duplicate | Flag | PURGE

Java - 0of 0 votes

AnswersWrite a program that controls the traffic signals for a four-way intersection. Initially, we consider traffic flowing in straight lines only, no turns. The four directions are S(outhbound) and N(orthbound) on Snell Rd; and W(estbound) and E(astbound) on Weaver Rd. The traffic lights should obey the following rules:

- harshshukla54 April 15, 2018 in United States

1. Cars arrive in each direction on both roads (Snell and Weaver) at the rate of 1 car per second. That is, 4 cars approach the intersection each second.

2. Only one road (Snell or Weaver) can have a "green" light at one time.

3. It is acceptable for both roads to have the "red" light at the same time. Of course, traffic backs up on both roads if this happens.

4. Start by turning on the traffic on Snell Rd "green" in both directions for 3 seconds; then turn it "red" for one second; then turn Weaver "green" for 3 seconds; and then red for one second.

5. When the light turns from red to green at any intersection, it takes the first car 2 seconds to start moving and cross the intersection. Subsequent cars take 1 second each.

6. At the instant the light turns from "green" to "red", a car may not start moving to cross the intersection; whether that car just arrived at the intersection or was waiting at that intersection.

7. The output should be the number of cars that are waiting at the intersection in each direction at each second, for the first 20 seconds. Do not make the program wait 20 seconds to produce the output: this is only a simulation, so print the output when it's ready.

8. Expected output

```

0: N = 0; S = 0; E = 0; W = 0

1: N = 0; S = 0; E = 1; W = 1

2: N = 0; S = 0; E = 2; W = 2

3: N = 0; S = 0; E = 3; W = 3

4: N = 1; S = 1; E = 4; W = 4

5: N = 2; S = 2; E = 5; W = 5

6: N = 3; S = 3; E = 5; W = 5

7: N = 4; S = 4; E = 5; W = 5

8: N = 5; S = 5; E = 6; W = 6

```| Report Duplicate | Flag | PURGE

Java - 0of 0 votes

AnswersDenver International Airport has decided to give an automated baggage system another shot. The hardware and tracking systems from the previous attempt are still in place, they just need a system to route the baggage. The system will route baggage checked, connecting, and terminating in Denver.

- harshshukla54 April 15, 2018 in United States

You have been asked to implement a system that will route bags to their flights or the proper baggage claim. The input describes the airport conveyor system, the departing flights, and the bags to be routed. The output is the optimal routing to get bags to their destinations. Bags with a flight id of “ARRIVAL” are terminating in Denver are routed to Baggage Claim.

Input: The input consists of several sections. The beginning of each section is marked by a line starting: “# Section:” ``` Section 1: A weighted bi-directional graph describing the conveyor system. Format: <Node 1> <Node 2> <travel_time>

Section 2: Departure list Format: <flightid> <flightgate> <destination> <flighttime> Section 3: Bag list Format: <bagnumber> <entrypoint> <flightid> ```

Output: The optimized route for each bag `

The output should be in the same order as the Bag list section of the input.

Example Input: ```

Section: Conveyor System

ConcourseATicketing A5 5 A5 BaggageClaim 5 A5 A10 4 A5 A1 6 A1 A2 1 A2 A3 1 A3 A4 1 A10 A9 1 A9 A8 1 A8 A7 1 A7 A6 1

Section: Departures

UA10 A1 MIA 08:00 UA11 A1 LAX 09:00 UA12 A1 JFK 09:45 UA13 A2 JFK 08:30 UA14 A2 JFK 09:45 UA15 A2 JFK 10:00 UA16 A3 JFK 09:00 UA17 A4 MHT 09:15 UA18 A5 LAX 10:15

Section: Bags

0001 ConcourseATicketing UA12 0002 A5 UA17 0003 A2 UA10 0004 A8 UA18 0005 A7 ARRIVAL ```

Example Output: `

0001 Concourse_A_Ticketing A5 A1 : 11 0002 A5 A1 A2 A3 A4 : 9 0003 A2 A1 : 1 0004 A8 A9 A10 A5 : 6 0005 A7 A8 A9 A10 A5 BaggageClaim : 12| Report Duplicate | Flag | PURGE

Java - 0of 0 votes

AnswerGiven list of schedules for different flights in a month, determine maximum number of flights that can be in the air anytime in that month.

- sanjureddy.v April 14, 2018 in United States

Input : list of schedules for flights.- spread over a month.

output: a number - maximum flights that can be in the air

Assumptions: 1. All the given times are in a specific timezone( like GMT).

2. Given Schedules can be any time in the month| Report Duplicate | Flag | PURGE

Google SDE1 Algorithm - 0of 0 votes

AnswerGiven a list of N threads detect a deadlock in the system.

- jddjjd007 April 12, 2018 in United States| Report Duplicate | Flag | PURGE

Google Algorithm - 0of 0 votes

AnswersFind the kth missing element in a sorted array. For example [2,3,5,7], k = 0: return 4, k = 1: return 6

- ajay.raj April 12, 2018 in United States

expected time complexity logn| Report Duplicate | Flag | PURGE

Amazon Backend Developer - 0of 0 votes

AnswersGiven an array of n elements return true if 3 of the sum of 3 elements is equal to a constant c

- mapardotl April 10, 2018 in United States for Facebook groups

Example array a[6,2,3,4] constant c = 9

if a[1] + [2] + [3] == c return true

The size of the array is n

If any set of 3 elements is equal to the constant c, then return false| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Java - 0of 0 votes

AnswersTo an array and K, each element in the array can only move K positions to the left at most, no limit to the right, try to sort the array under the limit of K

- ajay.raj April 10, 2018 in United States

a = [5, 2, 4, 3, 1], k = 2

Return [2, 3, 1, 4, 5]| Report Duplicate | Flag | PURGE

Amazon SDE1 - 0of 0 votes

AnswersGiven a function rand32() (random number range 0-2**32-1) that randomly generates a 32-bit int, design a new random function:

- ajay.raj April 09, 2018 in United States

Randn(n) generates a random distributed random number (0 - 2**n-1)

Rand3n(n) generates (0 - 3**n-1) the uniformly distributed random number| Report Duplicate | Flag | PURGE

Amazon SDE1

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window