## Recent Interview Questions

- 0of 0 votes

AnswersGiven a

`struct drop{ float x_cordinate; float radius; }`

Return the number of calls that the function Drop() that returns a drop object, needs to be called so that the interval [0, 1) is covered. For each drop object the range covered are values on a line considering x_cordinate as center and radius as the length added on both sides of the x_cordinate on that line?

`int numCalls(const function<drop> Drop){ drop firstDrop = Drop(); // Code from here }`

For example, if the first Drop() call returns drop object drop.location as 0.5 (considering points on a 1d axis) and drop.radius as 0.2, then the interval covered is [0.3, 0.7). So how many calls need to be made to ensure the interval [0, 1) is covered. The location and radius can map to any real value.

- rahul January 21, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer Intern - 2of 2 votes

AnswersGiven a list of arrays of time intervals, write a function that calculates the total amount of time covered by the intervals.

- aonecoding4 January 19, 2019 in United States

For example:

input = [(1,4), (2,3)]

return 3

input = [(4,6), (1,2)]

return 3

input = {{1,4}, {6,8}, {2,4}, {7,9}, {10, 15}}

return 11| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 0of 0 votes

AnswersYou are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

- User042891 January 17, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Intern - 0of 0 votes

Answersgiven an array representing a non-negative integer (ex: 123 represented as [1,2,3]), return the next integer (output: [1,2,4]).

- User042891 January 17, 2019 in United States

run through all edge cases (ex: [9,9,9,9,9,9,9,9] etc)| Report Duplicate | Flag | PURGE

Facebook Intern - -1of 1 vote

AnswersComplicated problem statement but was asked to implement binary search

- User042891 January 17, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Intern - -1of 1 vote

AnswersSparse Scalar vector dot product.

- User042891 January 17, 2019 in United States

in less than O(n)| Report Duplicate | Flag | PURGE

Facebook Intern - 0of 0 votes

AnswersWrite a uniform random function generator from 1 to n, given a uniform random Boolean generator, which return true or false for a given number randomly.

- SRC January 17, 2019 in United States| Report Duplicate | Flag | PURGE

- 0of 0 votes

AnswersGiven a graph in which there is an edge between (u,v) if gcd(u,v)>g . Given queries of u,v find if a path from u,v exists

- manaranjanfav January 17, 2019 in United States| Report Duplicate | Flag | PURGE

Algorithm - 2of 2 votes

AnswersWrite a new data structure, "Dictionary with Last"

- Coder January 15, 2019 in United States

Methods:

set(key, value) - adds an element to the dictionary

get(key) - returns the element

delete(key) - removes the element

last() - returns the last key that was added or read.

In case a key was removed, last will return the previous key in order.| Report Duplicate | Flag | PURGE

Facebook Software Engineer Data Structures - 1of 1 vote

AnswersGiven a grid M x N cells having weight in each cell(any integer),

- keviIma January 15, 2019 in United States

For every path from TOP-LEFT to BOTTOM-RIGHT, find the minimum weight you come across.(Minimum per path.)

Now from all those minimum weights, find the Maximum.

You can move in all 9 directions.

Is this a trick question?| Report Duplicate | Flag | PURGE

Amazon - 1of 1 vote

AnswersGiven an integer S, you have to count the total number of integral solutions of the equation a+b^2+c^3+d^4<=S, such that 0<=a,b,c,d<=10000 and 0<S<10^15

- Ankita January 13, 2019 in United States

Edit: Here value can be less than or equal to S, so if input S= 2 ,then output=12

i.e we can consider 0,0,0,1 and 0,0,0,0 etc also as sum will be less than S(i.e 2)| Report Duplicate | Flag | PURGE

SDE1 Algorithm - 0of 0 votes

AnswersGiven two strings Y and Z , return True if y beats z or z beats y .

- saurabh January 10, 2019 in India

Beating Criteria : for i in [1,N] y[i]>=z[i] , if this condition is true for any of permutations of y for any of the permutations of z .| Report Duplicate | Flag | PURGE

Directi Software Engineer Algorithm - 2of 2 votes

AnswersGet the sum of all prime numbers up to N. primeSum(N).

- aonecoding4 January 07, 2019 in United States

Follow-up: If primeSum(N) is frequently called, how to optimize it.| Report Duplicate | Flag | PURGE

Amazon - -5of 5 votes

AnswersFind a pair that equals to the given target from the list of given two lists.

- sarunreddy82 January 07, 2019 in United States

example:

input:

target = 7

list1= [[1,2],[2,4[,[3,6]]

list2 = [[1,2]]

Output:[[2,1]]

Explanation: There are only three combinations [1,1],[2,1] and [3,1], which use a total of 4,6, 8 respectively. Since 6 is the largest use that does not exceed 7, [2,1] is the only optimal pair.

Example 2:

Input :

target = 10

list1 = [[1,3],[2,5],[3,7],[4,10]]

list2 = [[1,2],[2,3],[3,4],[4,5]]

Output;

[[2,4],[3,2]]| Report Duplicate | Flag | PURGE

Amazon Arrays - 0of 0 votes

AnswerHow to divide a circular array into k group of contiguous element such that difference between maximum sum and minimum sum is minimum. Each group have contiguous element of array. For e.g If the array is as follow. [6 13 10 2] and k=2 then o/p should be 18(6+10+2)-13=5. As array is circular 6,10,2 are contiguous element of array.

- him4211 January 05, 2019 in India

For e.g If the array is as follow. [6 13 2 10] and k=2 then o/p should be 16(6+10)-15(13+2)=1. As array is circular 6,10 are contiguous element of array.

For e.g If the array is as follow. [100 92 133 201 34 34 34 94 108] and k=4 then group as follow 208(108,100), 225(92,133), (201), 196(34,34,34,94) so 225-196=29| Report Duplicate | Flag | PURGE

Samsung Software Developer Algorithm - 1of 1 vote

AnswersPrroblem: write an algorithm to calculate the minimum cost to add new roads between the cities such that all the cities are accessible from each other

int numTotalAvailableCities = 6;

int numTotalAvailableRoads = 3;

int[,] roadsAvailable = { { 1, 4 }, { 4, 5 }, { 2, 3 } };

int[,] costNewRoadsToConstruct = { { 1, 2,5 }, { 1,3,10 }, {1,6,2} ,{ 5, 6, 5 } };

int numNewRoadsConstruct = 4;

- sunil.sebastian January 05, 2019 in United States`public class MinimumCostToConstructNewRoad { public static int getMinimumCostToConstruct(int numTotalAvailableCities, int numTotalAvailableRoads, int[,] roadsAvailable, int numNewRoadsConstruct, int[,] costNewRoadsConstruct) { int totalCost = 0; bool[] Visited = new bool[numTotalAvailableCities]; int[] Keys = new int[numTotalAvailableCities]; int[] Parent = new int[numTotalAvailableCities]; int[,] AdjMatrix = GetAdjecencyMatrix(roadsAvailable, costNewRoadsConstruct, numTotalAvailableCities); for (int i=0;i< numTotalAvailableCities;i++) { Keys[i] = Int32.MaxValue; } Keys[0] = 0; Parent[0] = -1; for(int i=0;i< numTotalAvailableCities-1;i++) { var u = FindMin(Visited, Keys); Visited[u] = true; for(int v=0;v< numTotalAvailableCities;v++) { if(Visited[v]==false && AdjMatrix[u, v]!=Int32.MaxValue && AdjMatrix[u,v]<Keys[v]) { Parent[v] = u; Keys[v] = AdjMatrix[u, v]; } } } for(int i=1;i< numTotalAvailableCities;i++) { totalCost = totalCost + AdjMatrix[Parent[i], i]; } return totalCost; } private static int FindMin(bool[] Visited, int[] Keys) { int min = Int32.MaxValue; int index = -1; for (int i = 0; i < Keys.Length; i++) { if (Visited[i] == false && Keys[i] < min) { min = Keys[i]; index = i; } } return index; } private static int[,] GetAdjecencyMatrix(int[,] roadsAvailable, int[,] costNewRoadsConstruct,int numTotalAvailableCities) { int[,] AdjMatrix = new int[numTotalAvailableCities, numTotalAvailableCities]; for (int i = 0; i < numTotalAvailableCities; i++) { for (int j = 0; j < numTotalAvailableCities; j++) { AdjMatrix[i, j] = Int32.MaxValue; } } int count = 0; for (int i = 0; i < roadsAvailable.GetLength(0); i++) { int start = roadsAvailable[i, count]-1; int end = roadsAvailable[i,count+1]-1; AdjMatrix[start, end] = 0; } for (int i = 0; i < costNewRoadsConstruct.GetLength(0); i++) { int start = costNewRoadsConstruct[i, count]-1; int end = costNewRoadsConstruct[i, count+1]-1; int cost= costNewRoadsConstruct[i, count + 2]; AdjMatrix[start, end] = cost; } return AdjMatrix; } }`

| Report Duplicate | Flag | PURGE

Amazon SDE-2 Data Structures - 0of 0 votes

AnswerMaximum Pairs

You are given N pencils. You have to make pairs of pencils.

The condition for making pairs is:

If(a,b) is any pair of pencils then b >= 2 * a. Here a and b are the sizes of pencils.

Now you have to find out the number of such pairs and the number of pencils which could not be paired with any pencils.

Note:

You need to pair the pencils in such a manner that the maximum number of pairs are formed.

Input Format:

The first line consists of number of test case T.

Each test case consist of:

- First line consists of a single integer N.

- Second line consists of N space-separated integers denoting the size of pencils Si.

Output Format:

For each test case, print two space-separated integers, first denoting the number of pairs formed and second denoting the number of unpaired pencils.

Answer for each test case should come in a new line.

Constraints

1<T<=10

1<=N<=10^5

0<=Si<=10^5

Sample Input

2

5

1 2 3 4 5

4

1 2 4 4

Sample Output

2 1

2 0

Explanation

In the first test case:-

we can form the following pairs:

(1, 3), (2, 4) and 5 remains unpaired hence maximum pairs are 2

In second test case:-

(1, 4), (2, 4) are two pairs hence no pencil left unpaired

- Karan Khosla January 04, 2019 in United States for 4`public class Test { public static void main(String[] args) { } static int[] solve(int[] arr) { // the value at first index of array to be returned is number of pairs // formed and value at second index is unpaired swords. } }`

| Report Duplicate | Flag | PURGE

Java Developer Java - 0of 0 votes

AnswersGiven a target number and a single number, write a program to find the shortest path to calculate the target number by applying "+-*/" operations to the single number. No parentheses. For example, if we have target number=26 and single number=3 return 3 * 3 * 3 - 3 / 3.

- morfysster January 03, 2019 in United States| Report Duplicate | Flag | PURGE

Algorithm - 3of 3 votes

AnswersGiven a Start Node and an End Node in a graph report if they are “necessarily connected”. This means that all paths from the start node lead to the end node. Report true all paths from start node lead to end node and false if at least one path does not lead to the end node. This is a directed graph which can have cycles

- nikki December 31, 2018 in United States

Does anyone know how to solve this? I had it in my interview at Google in CA and I still cant solve it| Report Duplicate | Flag | PURGE

Google SDE1 Algorithm - 0of 0 votes

Answershow would you debug a tablet with a part of its touch screen is broken.

- rakshith18n December 31, 2018 in United States| Report Duplicate | Flag | PURGE

Amazon SDET - 0of 0 votes

AnswersGiven an arbitrary tree remove nodes which have data value 0.

- keviIma December 31, 2018 in United States

As it stats arbitrary tree, I assumed n-ary tree.| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 0of 0 votes

AnswersDesign a Google Sheet System?

- xyz December 28, 2018 in United States

Where do you store the data? sql or nosql

How do you maintain concurrency?

How do you display it in frontend, which can be inline editable?| Report Duplicate | Flag | PURGE

rallyhealth Backend Developer System Design - 0of 0 votes

Answers* Build Offices

- keviIma December 26, 2018 in United States

A company wants to develop an office park in an area that has been divided up into a grid where each cell represents a potential building lot. The goal is for the furthest of all lots to be as near as 1 possible to an office building. Determine the building placement to minimize the distance the 0 most distant lot is from an office building. Movement is restricted to horizontal and vertical, i.e. diagonal movement is not allowed.

For example, there are n = 3 office buildings to build on a grid that is w = 4 lots wide and h = 4 lots high. An optimal grid placement sets any lot within two units distance of an office building. In the distance grid below, offices are cells at distance 0.

1 0 1 2

2 1 2 1

1 0 1 0

2 1 2 1

That represents one optimal solution among several, this array rotated for example.

The function must return an integer that denotes the maximal value among shortest distances to the closest office for each cell.

findMinDistance has the following parameter(s): w: an integer, the width of the grid h: an integer, the height of the grid n: an integer, the number of buildings to place

Constraints:

wxh <= 28| Report Duplicate | Flag | PURGE

- 0of 0 votes

AnswersIn an interview this question has been asked :

- S@iR@m December 26, 2018 in India

How to fit four characters into an integer, implementation should be in C programming language.

For example, four characters, viz., 'a', 'b', 'c', and 'd' need to be fit into an integer.

I tried to answer this question using ASCII value of the characters.

Please suggest the correct solution.| Report Duplicate | Flag | PURGE

Not disclosed Tech Lead C - 1of 1 vote

AnswerGiven a series of equations e.g. [A = B, B = D, C = D, F = G, E = H, H = C]

- aonecoding4 December 25, 2018 in United States

and then another series [A != C, D != H, ..., F != A ]

Check whether the equations combined is valid.

For the example given, your program should return 'invalid', because the first series implies that A = C, which contradicts the statement A != C in the second series.| Report Duplicate | Flag | PURGE

Amazon Software Engineer - 0of 0 votes

AnswersA function receives a big array (about 1G).

- amitaiweil December 23, 2018 in Isreal

after manipulations done on the array it's data

will be erased. What should you're attitude be to dealing with the array? (I didn't understand totally the interviewer's meaning| Report Duplicate | Flag | PURGE

צבאד Software Engineer C - 0of 0 votes

Answersread the 5'th bit from a byte

- amitaiweil December 23, 2018 in Isreal| Report Duplicate | Flag | PURGE

צבאד Software Engineer C - 0of 0 votes

AnswerWrite a function which returns

- amitaiweil December 23, 2018 in Isreal

the multiplication of two inputs,

without using "return"| Report Duplicate | Flag | PURGE

צבאד Software Engineer C - 0of 0 votes

AnswersImagine you have a computer keyboard that has all the letters mismatched

- klausv December 23, 2018 in United States

example:

typing q gives you a

typing w gives you b

all 26 letters in the alphabet are there, but typing one letter will give you another one

you are asked to write an algorithm to find whatever word you tried to type and count how many cycles you did to find the word

a restriction was set you need to type the whole word every time, not go character by character

note: a graph was suggested to represent the letter mappings| Report Duplicate | Flag | PURGE

Amazon SDE-2 Trees and Graphs - 1of 1 vote

AnswersReplace each number by its next bigger number from right side of current index. if no bigger number found print that number itself.

- SRC December 19, 2018 in India

Eg: 2,5,9,6,3,4,8,15,12

OutPut : 3,6,12,8,4,8,12,15,12| Report Duplicate | Flag | PURGE

Oracle Backend Developer

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

Open Chat in New Window