## Algorithm Interview Questions

- 0of 0 votes

AnswerSolve the 24 Game

- aonecoding August 14, 2017 in United States| Report Duplicate | Flag | PURGE

Twitter Software Engineer Algorithm - 3of 3 votes

AnswersRound4

- aonecoding August 09, 2017 in United States

Starting from num = 0, add 2^i (where i can be any non-negative integer) to num until num == N. Print all paths of how num turns from 0 to N.

For example if N = 4,

Paths printed are [0,1,2,3,4], [0,1,2,4], [0,1,3,4], [0,2,4], [0,2,3,4], [0,4].

[0,2,4] is made from 0 + 2^1 + 2^1. [0,1,3,4] from 0 + 2^0 + 2^1 + 2^0| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersRound3

- aonecoding August 09, 2017 in United States

For N light bulbs, implement two methods

I. isOn(int i) - find if the ith bulb is on or off.

II. toggle(int start, int end)| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersRound1

- aonecoding August 09, 2017 in United States

Find if two people in a family tree are blood-related.

Round2

Given some nodes in a singly linked list, how many groups of consecutively connected nodes there is.

For linked list

0->1->2->3->4->5->6,

given nodes 1, 3, 5, 6

there are 3 groups [1], [3], and [5, 6].| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - -1of 1 vote

Answerscount number of combinations which are not possible.

- bit32413 August 05, 2017 in United States

There are 'n' empty slots.

A slot can be filled with 'O', 'E', or 'X'

A combination is possible if

1. 'O' s are placed in odd slot , 'E' a are placed in even slots.

2. 'O' and 'E' alternate among them,

i.e (OXOE) not allowed because between O s there is no 'E'; but (OEXXO) is allowed.

some allowed combinations

OEXXX, XXOEO, OXXEX

For 3 slots, not allowed combinations are

OXX

XXO

XEX

XXX

OXO

Only those combinations are considered in which O s and E s are in their respective odd and even slots.

i.e EEXXX will never be considered because a 'E' is in odd slot

A combination isn't allowed if 'O' is not followed by 'E' or vice versa| Report Duplicate | Flag | PURGE

Google SDE-2 Algorithm - 1of 1 vote

AnswersGiven a sorted distinct array of integers and a key K. C closest elements to K are in range [L,R] inclusive, L<=R. Return L as the left index of C closest elements to K.

- anonymous August 04, 2017 in United States

For example:

A = [1, 2, 5, 8, 9, 13]. K = 8 and C = 4. The result L = 3 because 4 closest elements to 8 are [5, 8, 9, 13]| Report Duplicate | Flag | PURGE

Google Intern Algorithm - 0of 0 votes

AnswersGiven a tree print in level zig-zag order.

- tnutty2k8 August 03, 2017 in United States`Example suppose we have the given tree structure: 1 2 3 4 5 6 it should print: 1 3 2 4 5 6 First level prints left to right. Then next level prints right to left. Alternating for each level. Assume the following node structure: Node { data: Integer, left: Node, right: Node, parent: Node, }`

| Report Duplicate | Flag | PURGE

Algorithm - 1of 1 vote

AnswersRound 5:

- aonecoding August 03, 2017 in United States

Given a set of synonyms such as (fast, quick), (fast, speedy), (learn, study), decides if two sentences were synonymous.

(The sentences were structurally the same and has the same number of words in them.

The synonymous relation [fast ~ quick] and [fast ~ speedy] does not necessarily mean [quick ~ speedy].)

Follow-up:

If the synonymous relation passes down so that [fast ~ quick] and [fast ~ speedy] implies [quick ~ speedy], decide if two sentences were synonymous.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 1of 1 vote

AnswersRound 4:

- aonecoding August 03, 2017 in United States

Implement a class Employment with these 3 methods: assignManager(p1, p2): assign p1 as p2's manager. beColleague(p1, p2): make p1 and p2 peer colleagues. isManager((p1, p2): decide if p1 is the manager of p2.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersRound 3

- aonecoding August 03, 2017 in United States

Given a matrix of 0s and 1s where 0 is wall and 1 is pathway, print the shortest path from the first row to the last row.

Can walk to the left, top, right, bottom at any given spot.

Follow-up:

If every pathway takes a cost (positive integer) to get through, print the minimum cost path from the first row to the last row.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 1of 1 vote

AnswersGoogle on-site June

- aonecoding August 03, 2017 in United States

Round 1

Leetcode 10

Round 2

Select a random point uniformly within a rectangle, (The side of rectangle is parallel to the x/ y grid).

Follow-up: Given multiple non-overlapped rectangles on the 2D grid, uniformly select a random point from the rectangles.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersCompress String with character and its count.

- tnutty2k8 July 31, 2017 in United States

Example: "aaabbba" -> compress -> "a3b3a1”| Report Duplicate | Flag | PURGE

Web Developer Algorithm - 2of 2 votes

AnswersPhone Interview Amazon, Seattle

- aonecoding July 28, 2017 in United States

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

Follow-up: If primeSum(N) is frequently called, how to optimize it.

II. OODesign Parking Lot| Report Duplicate | Flag | PURGE

Amazon Software Engineer Algorithm - 2of 2 votes

AnswersApple Map Team

- aonecoding July 25, 2017 in United States

1. Given an array A and some queries, query(i, j) returns the result of Ai*...*Aj, in other words the multiplication from Ai to Aj.

The numbers in A are non-negative.

Implement query(i, j).

2. Flatten nested linked list

3. POI search design

4. LC238 & LC279| Report Duplicate | Flag | PURGE

Apple Software Engineer Algorithm - 1of 1 vote

AnswersAirbnb Interview

- aonecoding July 25, 2017 in United States

Min cost of flight from start to end if allowed at most k transfers.

Given all the flights in a string:

A->B,100,

B->C,100,

A->C,500,

If k = 1，from A to C the best route is A->B->C at the cost of 200.| Report Duplicate | Flag | PURGE

Airbnb Algorithm - 2of 2 votes

AnswersYou are given an old touch smartphone numbers having dial pad and calculator app.

- neovivek14 July 23, 2017 in United States

Aim: The goal is to type a number on dialpad.

But as phone is old, some of the numbers and some operations can't be touched.

For eg. 2,3,5,9 keys are not responding , i.e you cannot use them

But you can always make a number using other numbers and operations in Calculator. There could be multiple ways of making a number

.Calculator have 1-9 and +,-,*,/,= as operations. Once you have made the number in Calculator you can copy the number and use it.

You have to find minimum number to touches required to obtain a number.

#Input:#

There will be multiple Test cases .Each test case will consist of 4 lines

1) First line will consist of N,M,O

N: no of keys working in Dialpad (out of 0,1,2,3,4,5,6,7,8,9)

M:types of operations supported (+,-,*,/)

O: Max no of touches allowed

2) second line of input contains the digits that are working e.g 0,2,3,4,6.

3) Third line contains the valued describing operations, 1(+),2(-),3(*),4(/)

4) fourth line contains the number that we want to make .

#Output:#

Output contains 1 line printing the number of touches required to make the number

#Sample Test Case:#

1 // No of test cases

5 3 5 // N ,M, O

1 2 4 6 0 // digits that are working (total number of digits = N),

1 2 3 // describing operations allowed (1--> '+', 2--> '-', 3--> '*' , 4--> '/' )(total number is equals to M)

5 // number we want to make

Answer 3

How 4? 1+4= , "=" is also counted as a touch

2nd Sample Case

3 // No of Test cases

6 4 5 // N ,M, O

1 2 4 6 9 8 // digits that are working (total number of digits = N),

1 2 3 4 // describing operations allowed (1--> +, 2--> -, 3--> , 4-->/)

91 // number we want to make

6 2 4 // 2nd test case

0 1 3 5 7 9

1 2 4 // +, -, / allowed here

28

5 2 10

1 2 6 7 8

2 3 // -, allowed

981

#Output:#

2 // 91 can be made by directly entering 91 as 1,9 digits are working, so only 2 operations

5// 35-7=, other ways are 1+3*7=

9//62*16-11=

Order for computation will be followed as symbols entered, if + comes, it will be computed first

One more example: lets say 1,4,6,7,8,9 works and +,-,* works.

2,3,5 and / doesn't work.

If you have to type 18-> 2 operations. (Each touch is considered an operation),br> If you have to type 5 -> '1+4=' that requires 4 operations. There could be other ways to make '5'.| Report Duplicate | Flag | PURGE

Samsung Software Engineer Algorithm - 3of 3 votes

AnswersApple phone interview

- aonecoding July 23, 2017 in United States

Given an API to find all IPv4 addresses in a log file, find all IPs that occurred only once.

Follow-up: What if the log comes from a data stream.

Follow-up: If the machine has 4GB RAM, is there going to be a problem?| Report Duplicate | Flag | PURGE

Apple Backend Developer Algorithm - 0of 0 votes

AnswersThe memmove() function copies n bytes from memory area src to memory area dest. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest.

- jaya.ppatil July 21, 2017 in United States for AWS| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersSuppose there are N number of clusters, B number of machines and number of tasks in clusters are stored in an array named a. The goal is to minimize the single most overloaded machine and every cluster must be given at least one machine. Output should be one integer representing the number of the tasks in the busiest machine (rounded up).

- dizhu2016 July 20, 2017 in United States

1<=N<=500000

N<=B<=2000000

1<=ai<=5000000

for example, N=2,B=7, a=[200,450], output should be 100.

Any ideas?

Thanks| Report Duplicate | Flag | PURGE

Algorithm - 2of 2 votes

Answers4/5 Round at Uber

- aonecoding July 20, 2017 in United States

Coding: Given a 2D array of either '\' or '/', find out how many pieces this rectangle is divided into graphically.

For a 2X2 matrix with

/\

\/

The matrix split into 5 pieces - the diamond in middle and the four corners. Return 5 as the answer.

5/5 Round at Uber

Design Excel.| Report Duplicate | Flag | PURGE

Uber Software Engineer Algorithm - 1of 1 vote

Answers2/5 Round at Uber

- aonecoding July 20, 2017 in United States

Bar raiser - Behavioral questions. Coding: Find if a set of meetings overlap. Meeting has a starttime and an endtime with accuracy to minute. All meetings take place in the same day. Do this in O(n) time.

3/5 Round at Uber

Coding: Subset sum. Follow-up: Optimize the solution.| Report Duplicate | Flag | PURGE

Uber Software Engineer Algorithm - 2of 2 votes

AnswerUber

- aonecoding July 17, 2017 in United States

1. Mirror Binary Tree

2. String pattern matching

The matching should cover the entire input string (not partial).

The function prototype should be:

bool isMatch(String str, String pattern)

Some examples:

isMatch("aa","a") → false

isMatch("aa","aa") → true

isMatch("aaa","aa") → false

isMatch("aa","a{1,3}") → true

isMatch("aaa","a{1,3}") → false

isMatch("ab","a{1,3}b{1,3}") → true

isMatch("abc","a{1,3}b{1,3}c") → true

isMatch("abbc","a{1,3}b{1,2}c") → false

isMatch("acbac","a{1,3}b{1,3}c") → false

isMatch("abcc","a{1,3}b{1,3}cc{1,3}") → true

In pattern string, a char followed by {lower, upper} means that the char occur lower to upper(exclusive) times. e.g. a{1, 3} -> a occurs 1 or 2 times.| Report Duplicate | Flag | PURGE

Uber Software Engineer Algorithm - 3of 3 votes

Answers3.1 design: design fb inbox search —> just focus on the post

- aonecoding July 15, 2017 in United States

4.1 binary tree to circular double linked list.

4.2 two arrays, find the common elements of two sorted array. if one array is small, the other is very big.| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 2of 2 votes

Answers2.1 career discussion

- aonecoding July 15, 2017 in United States

2.2 divide two numbers with no / or %| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 4of 4 votes

Answers1/4 round of FB on-site interview, Master Degree, Hired

- aonecoding July 15, 2017 in United States

1.1 diameter of tree

1.2 find the point which have the maximum overlap of intervals| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 0of 0 votes

AnswersPhone interview question from January.

We have a maze with three types of spaces:

1. Walls

2. Offices

3. Hallway space

Given a maze, determine which non-wall space would minimize the sum of all distances between that space and every office. You can only move up, down, left, and right.

(Edit: ChrisK described the problem more clearly than I did: "find the field that minimizes the sum of the shortest path[s] from this field to each office space.")

Example:`WWWWWWWW WWW O WW WWW OW WWW WWWW WO WWWW WWW WWWW WO W WWWWWWWW`

O = office, W = wall, spaces are hallway spaces

- mbs729 July 13, 2017 in United States

You can represent the maze however you want. That is, you can use any data structures you want, and you don't necessarily have to use O for office, W for Wall, and spaces for hallways.

(I'm not sure if you can actually start from an office space, but that should be a trivial issue because you can always just start a position adjacent to an office.)| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 3of 3 votes

Answers1 year exp. Interviewed at Cambridge, MA

- aonecoding July 11, 2017 in United States

Round1

LC304. Follow-up: given a char stream instead a string as the input, get the longest substring with at most K distinct characters.

Round2

Find out the area of a number of squares on a plane, an advanced version of LC223.

Had no clue on that problem at all so the interviewer kindly gave another one LC305.

Round3

Similar to LC393 but the interviewer made a slightly different rule for encoding.

Follow-up: decode with utf-16. It took quite a while for me to understand the rules.

Round4

Card game rule: the hand is drawn from a pack of cards (no jokers).

Play cards ONLY when they are

1. 3 of a kind ('AAA' ) or 4 of a kind('AAAA’).

2. a straight flush of 3 or more cards('JQK' or 'A23456...' in the same suit).

Find out whether the player is able to play the whole hand given.

e.g. [Spade A, Spade K, Spade Q, Diamond Q, Heart Q] return false.

[Spade A, Spade K, Spade Q, Diamond Q, Heart Q, Club Q] return true.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersIdentifying if all the elements of a set (in enterity) is present in a list of sets.

- hulk July 11, 2017 in India

For example checking for set1 = {1,2} in {1,2,3}, {5,6} should return true as {1,2} is present in {1,2,3}. Similiary it will be true for {1,2,8,9}, {1,2,4}

But checking for {1,2} in {1,5,6}, {2,3,1} should return false as {1,5,6} does not contain all elements of {1,2} 2 is missing| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm

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

Open Chat in New Window