## Algorithm Interview Questions

- 0of 0 votes

AnswersGiven integer m and n where n is odd, for all mxn matrixes that consist of 0 and 1, find the one that has max count of 1s and meets following conditions:

- akak18183 August 31, 2018 in United States

1. All 0s are connected;

2. All 1s are adjacent to at least one 0 (Adjacent includes diagonal line adjacent, 8 directions);

3. maxtrix[m-1][n/2] = 0.

Example :

Input: m=2, n=3

Output: [[1,1,1],[1,0,1]]

Follow up:

Given another list of 'blocked' points. Matrix will set those points to -1 and you cannot change that. Solve the problem again.| Report Duplicate | Flag | PURGE

unknown Software Engineer Algorithm - 0of 0 votes

AnswersWhat is idempotence and why is it useful for API design? (~2-6

- ruta.gadgil August 31, 2018 in United States for Penny

sentences)| Report Duplicate | Flag | PURGE

CreditKarma Software Engineer Algorithm - 0of 0 votes

AnswersLooking at this function, what bugs do you see or concerns do you have

- ruta.gadgil August 31, 2018 in United States for Penny

about its functionality? You can assume the models are correctly

{{defined, the schema is correct, etc. (~1-3 sentences)

def send_email_to_user_once!(to_user_id:, type:, subject:, body:)

user = User.find(to_user_id)

return if UserEmailLog.where(user_id: user.user_id, email: type).exists?

send_email(to: user.email, subject: subject, body: body)

UserEmailLog.create!(user_id: user.user_id, email: type)

end

def send_email(to:, subject:, body:)

# Makes a blocking network request to Amazon Simple Email Sender

# to send an email. Returns nothing in all cases.

# See this link for more info if you need it.

end}}| Report Duplicate | Flag | PURGE

CreditKarma Software Engineer Algorithm - 0of 0 votes

AnswersWhat does this Javascript ES6 function do and how is it useful? If you

- ruta.gadgil August 31, 2018 in United States for Penny

had to give the function a name, what would it be? (~1-2 sentences)

{{

function operate(l, s, callback) {

a = s

for (let i = 0; i < l.length; i++) {

a = callback(a, l[i])

}

return a

}

}}| Report Duplicate | Flag | PURGE

CreditKarma Software Engineer Algorithm - 4of 4 votes

AnswersYou are given a campus map with the Google buildings, roads and Google

bikes. You have to help the employee find the nearest Google bike.

Campus map:

- john August 29, 2018 in United States`. - Free path/road # - Building B - Google bike Employee location - (x, y) - (1, 2) . . . . . # . . E . . # # # # # . # . B . . . . . . . . . B`

| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersFor a given amount of currency, find the minimum set of bills. The currency set is the following: 0.01, 0.05, 0.1, 0.25, 1, 5, 10, 20, 50, and 100. For example, for 21.28, 1 20 bill, and 1 1 bill, and 1 0.25 bill and 3 0.01 bills.

- fz August 09, 2018 in United States| Report Duplicate | Flag | PURGE

Software Developer Algorithm - 0of 2 votes

AnswersWhat is the best way to generate first N primes? (not primes up to N but first N primes)

- koustav.adorable July 22, 2018 in United States for Amazon Prime| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

Answer**Game of Bits**

- harshit.knit July 19, 2018 in India

Yale and Xavier are playing a game with numbers. Each round of the game starts with a number given to them by Zita, Yale’s little sister.

The number n is expressed as a binary integer with p bits

For every round, Xavier gets the first move.

The game came consists of moves performed by Yale and Xavier alternately.

The mth move of the game involves performing these operations on the number:

Toggling the mth bit (numbering of bits starts from left) of the number.

Toggling the left adjacent bit of m (if such a bit exists) if it is equal to the mth bit before toggling in step 1; otherwise keep it as is.

Toggling the right adjacent bit of m (if such a bit exists) if it is equal to the mth bit before toggling in step 1; otherwise keep it as is.

This modification of the number goes on until all p moves are made. If the modified number (as a result of all the operations) is

equal (or a distance one away) from the original number, then the person who made the last move wins the round; otherwise the other one wins the round.

**Note:**

The number given to them is converted to its binary form and represented with the help of minimum number of bits.

The numbering for the bits starts from the leftmost bit.

**Constraints**

1<=r<=10^6

1<=n<=10^6, where n is the number given by Zita in any round

**Input Format**

The first line contains a number, r, denoting the number of rounds in the game.

This is followed by r lines, where the ith line contains the number given by Zita for the ith round.

**Output Format**

The output of the problem has r lines, where the ith line contains the winner of ith round as X if Xavier wins ith round or Y if Yale wins the ith round.

**Sample Input**

1

11

**Sample Output**

Y

**Explanation**

11 is represented as 1011 using minimum number of bits in binary.

When Xavier makes the first move, it becomes 0011.

Then Yale makes the 2nd move and it becomes 1111.

After the third move made by Xavier, it becomes 1000.

After the last move by Yale, it becomes 1011 which is 11 in decimal.

The last move was made Yale and the modified number is equal or adjacent to 11,

therefore, Yale wins this round.| Report Duplicate | Flag | PURGE

ThoughtWorks Software Engineer / Developer Algorithm - 0of 0 votes

AnswerYou have been given a string and a number. You need to find the longest common suffix between string and substring(0 to number)

- sandeepmnit35 July 10, 2018 in United States

Example : String = "ababa"

Number is 3

Take a substring from 0 to 2 which is aba

now find the longest matching suffix between "ababa" and "aba"| Report Duplicate | Flag | PURGE

Computer Scientist Algorithm - 1of 1 vote

AnswersI don't remember perfectly the question, but it was like this

- mmoshikoo July 10, 2018 in Israel

Given a list of 100 songs on your cell phone, find a way for each user to hear the songs without repeating songs, you need to use an algorithm that uses shuffle for songs.| Report Duplicate | Flag | PURGE

Microsoft Software Developer Algorithm - 2of 2 votes

AnswersGiven 2 strings representing very large numbers (these are not representable as a BigInteger or other various type) write a method for adding the two numbers and returning their sum.

- Scott.T.Rogers July 06, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Senior Software Development Engineer Algorithm - 0of 0 votes

AnswersDesign and implement a interest matching algo, to match people according to their interests in a particular area.

- ANONU July 06, 2018 in United States

Suggest a score based on their interests. And rank matchings accordingly.| Report Duplicate | Flag | PURGE

Zynga Software Engineer Algorithm System Design - 2of 2 votes

AnswersIn a Binary maze with 0 and 1, 0 is the valid cell to which we can travel and 1 means that the cell is blocked. Given source and destination. We have to find-

- richa.cseit July 03, 2018 in India

1. IF path exists, if yes, find shortest path.

2. If we are given a chance to toggle single cell from 1 to 0 , which cell you will toggle so that you will surely get the shortest path.| Report Duplicate | Flag | PURGE

Uber SDE-3 Algorithm - 0of 0 votes

Answersset of locations on the map. Example, 4 places in zone 1. 2 places in zone2, 1 place in zone3 and 2 in zone4. 2 aircraft are assigned, A1, A2. A1 can fly faster. A2 is slower but farther than A1. Each day A1 can visit one location in any zone whereas A2 can visit 2 locations in any zone. what is the optimized number of visits by A1 and A2 at the end of 30 days.

- Geetha June 24, 2018 for Australia| Report Duplicate | Flag | PURGE

Capgemini Dev Lead Algorithm - 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

AnswerGiven an infinitely large array and every element has tags associated with them, and there are about 10,000 tags (say) then sort the given array to get all tag-0’s first, tag-1’s next and so on in O(n).

- Ankita June 10, 2018 in India| Report Duplicate | Flag | PURGE

Amazon SDE1 Algorithm - 0of 0 votes

Answerswater capacity in a histogram

- TonyStark June 08, 2018 in India

what is the capacity if an array value becomes 0 - which will make the water to flow off the histogram| Report Duplicate | Flag | PURGE

Algorithm - -1of 1 vote

AnswersReverse a linked list

- James666 June 06, 2018 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersFind Duplicate number from a huge amount of data which cannot fit in the memory.

- CodeNinja June 03, 2018 in United States| Report Duplicate | Flag | PURGE

Microsoft Software Developer Algorithm - 1of 1 vote

AnswersFind kth-largest number from a huge amount of data which cannot fit in the memory.

- CodeNinja June 03, 2018 in United States| Report Duplicate | Flag | PURGE

Microsoft Software Developer Algorithm - 0of 0 votes

AnswerGiven a random MxN matrix and a positive integer, recursively Your program should then find a continuous path thought the matrix starting at position 0,0 that will sum to n. Your program shouldomly move left (col -1), right(col +1), up (row -1) and down (row+1)and can only use a position once in the sum. if there is a such path in the matrix, create the path in a separate matrix with the same size, and replacing the indices used with 1 and the rest 0.

- stingerviii June 02, 2018 in United States| Report Duplicate | Flag | PURGE

Amazon Software Engineer Algorithm - 2of 2 votes

AnswersYahoo Sunnyvale onsite

- aonecoding May 28, 2018 in United States

A string s3 consists of multiple repetitions of s1.

Given s1 and another string s2, find if s2 is a substring of s3.

s3 = s1 + s1 + … + s1 = n * s1, where n is a positive integer 0.

For example

s1 = “aabc”, s2 = “caa” => true

s1 = “aabc”, s2 = “cab” => false

s1 = “aabc”, s2 = “caabcaa” => true| Report Duplicate | Flag | PURGE

Yahoo Software Engineer Algorithm - 1of 1 vote

AnswersA city represented by a rectangular matrix is divided into plot of lands, and the cost of each plot is known. Find the largest rectangular area of land we can buy, within a budget B.

- sachin323 May 27, 2018 in United States

4 6 7

3 5 2

2 4 5

B = 16| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 5of 5 votes

AnswersCongrats on aonecode member A.P. for signing the offer with FB! Thanks for sharing the experience with us.

- aonecoding May 24, 2018 in United States

phone:

postorder tree traversal recursive -> iterative

add two binary number

on-site:

1 ring buffer

2 merge intervals

3 Leetcode alien dictionary

4.sort list of words| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 2of 2 votes

AnswerAirbnb: Design webbrowser back button

- aonecoding May 23, 2018 in United States

Your web browser supports will support three actions: back, forward and open. The init webpage is “about:blank”.

Given a sequence of commands. Return the result page.| Report Duplicate | Flag | PURGE

Airbnb Software Engineer Algorithm - 0of 0 votes

AnswersYou have been given a generator string ab from which any number of strings can be generated recursively by inserting ‘ab’ at any location. You have been given an input string to check if that given string is valid or not.(i.e. generated by given with given string.)

- akisonlyforu May 22, 2018 in India

eg.

Input: aabbab

Output: valid

Input: abbaab

Output: Invalid

I could not come up with a algorithm less than O(N*N)| Report Duplicate | Flag | PURGE

Amazon SDE1 Algorithm - 0of 0 votes

AnswerSearch for a sorted integer in an integer array that has been rotated multiple times.

- teli.vaibhav May 14, 2018 in United States| Report Duplicate | Flag | PURGE

Samsung Senior Software Development Engineer Algorithm - 1of 1 vote

AnswersPrint the bottom view of a Binary Tree.

ex-`1 2 3 4 5 7 8 9 10`

result is 4, 8, 5, 9, 7, 10

- teli.vaibhav May 14, 2018 in United States| Report Duplicate | Flag | PURGE

Samsung Senior Software Development Engineer Algorithm - 0of 0 votes

AnswersGiven an alphabet where we do not know the order of the letters also do not know the number of letters.

- teli.vaibhav May 14, 2018 in United States

We are give an input list of tuples where each entry in the list gives an ordering between the 2 letters

Determine the alphabet order.

Ex-

<A, B>

<C, D>

<C, E>

<D, E>

<A, C>

<B, C>

Order is A, B, C, D, E| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 2of 2 votes

AnswersAWS phone interview

- aonecoding May 13, 2018 in United States

Find the left view of binary tree

1

/ \

2 3

/\ \

4 5 6

/ /

7 8

/

9

return [1, 2, 4, 7, 9]| Report Duplicate | Flag | PURGE

Amazon Software Engineer Algorithm

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

Open Chat in New Window