## Algorithm Interview Questions

- 1of 1 vote

AnswersAdd two numbers represented as LinkedList (not LeetCode 445 which uses ListNode)

- KelvinLong8897 November 17, 2018 in United States

e.g

inputs: '5'->'6'->'3'

'8'->'4'->'2'

output: '1'->'4'->'0'->'5'

method signature:

LinkedList<Integer> sumList(LinkedList<Integer> l1, LinkedList<Integer> l2)| Report Duplicate | Flag | PURGE

Facebook Android Engineer Algorithm - 0of 0 votes

AnswersProgram to find the rank student

- Rising star November 05, 2018 in United States| Report Duplicate | Flag | PURGE

unknown freshers Algorithm - 0of 0 votes

Answers1. Input string s. Check if string s is a valid string with valid brackets

- donkeysnore November 05, 2018 in United States

For example:

(({{}})) is a valid s

{[]} is a valid s

[{[}]] is not valid

2. What kind of tests would you conduct to your program to minimize bugs in your program.

3. On the previous example there is only "()", "{}", and "[]" combination of brackets. If other developers want to add a new kind of brackets such as "<>". What kind of changes would change in your previous program.| Report Duplicate | Flag | PURGE

Bloomberg LP Intern Algorithm - 0of 0 votes

AnswersGiven a matrix of 0's and 1's find the smallest number of groups made of 1's, where one group can cover up to two 1's at the same time vertically or horizontally.

- matk100.100 October 31, 2018

01111

11011

00100

The matrix above has 5 of such groups. I've seen similar questions but there the question was about groups of adjacent 1's. Here the groups are limited.

Another question how it would change, if the group wasn't limited to two but to given k - number of 1's vertically or horizontally. The time complexity should be the most efficient.

My idea here i to iterate through rows and when we find a 1, check it's bottom and right neighbour. If it has a right but no bottom, a group is made and we skip the right neighbour as it is already in a group. When the checked 1 has a bottom but no right, we make a group of them and we can skip checking the right as well i think.| Report Duplicate | Flag | PURGE

Algorithm - 2of 2 votes

AnswersGiven the root of a binary tree, print the nodes column wise and row wise.

`..............6 ............/....\ ...........9......4 ........../..\......\ .........5....1.....3 ..........\........./ ...........0.......7`

The answer would be 5 9 0 6 1 4 7 3.

- Champaklal October 26, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Software Developer Algorithm - 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

AnswersSuppose If you are hacker, you have to push data to server and find how much data server can accept using minimal number of times. We don't the size of how much server will accept.

- narsimharao.mothkuri October 14, 2018 in India| Report Duplicate | Flag | PURGE

Accolite software Applications Developer Algorithm - 1of 1 vote

AnswerGiven an array and threshold value. The threshold represents the maximum length of subarrays that may be created. Each subarray created has a cost equal to the maximum integer within the subarray. Partition the entire array into subarrays no longer than the threshold and do it at minimum cost. The subarrays are to be chosen from contiguous elements and the given array must remain in its original order. Write a function to return an integer that denotes the minimum cost to partition the array.

- sticker01 September 23, 2018 in United States

For more clarification, here are the test cases.

1. Array: [1,2], threshold: 1.

we divide the array to {(1),(2)} Total cost is 1+2 = 3

2. Array: [1,5,2], threshold: 2.

we divide the array to {(1),(5),(2)} with total cost 1+5+2 = 8. OR

we divide to {(1,5),(2)} with total cost 5+2 = 7 OR

we divide to {(1),(5,2)} with total cost 1+5 = 6.

Of these minimum total cost is 6. So the ans is 6 with subarrays as {(1),(5,2)}| Report Duplicate | Flag | PURGE

Algorithm - 0of 0 votes

AnswersA company wants to fly in a total of 100 candidates for the interview. The company has two office location, one in NY and other in SF and max capacity at each location is 50 candidates. You are given the cost it incurs to fly in each candidate to NY and SF.

`[500, 300],[540, 600],[550, 600],[300, 50]..so on`

Write an algorithm for the minimum total cost?

- nishug001 September 22, 2018 in United States| Report Duplicate | Flag | PURGE

Bloomberg LP Software Engineer Algorithm - 0of 0 votes

AnswersGiven 3 unsorted arrays A, B and C you need to find all possible combinations such that A[i] + B[j] = B[k] + C[l].

- venkataratnamkumar7777 September 22, 2018 in United States| Report Duplicate | Flag | PURGE

Walmart Labs SDE1 Algorithm Arrays - 1of 1 vote

AnswersLets there are n stores.

- sam September 18, 2018 in United States

A customer order x items. All the stores might not have all the items from the order list. So find the store/combination of stores that can serve the order request such that the set that contain least number of stores is selected so that there are lesser number of shipments.| Report Duplicate | Flag | PURGE

Software Developer Algorithm - 0of 0 votes

AnswersPascal Triangle Hockey Stick Identity?

- Pearl September 16, 2018 in United States| Report Duplicate | Flag | PURGE

Algorithm - 0of 0 votes

AnswersGiven an array of negative and positive integers, find the biggest sum of a sub-array.

- asiftasleem September 12, 2018 in United States| Report Duplicate | Flag | PURGE

Service Now Staff Engineer Algorithm - 0of 0 votes

AnswersGiven an array of integers and a target. Find the two array elements if they are summed up, will result in the target.

- asiftasleem September 12, 2018 in United States| Report Duplicate | Flag | PURGE

Service Now Staff Engineer Algorithm - 0of 0 votes

AnswersFind 2nd duplicate in an array

- interviewquestionsseeker September 07, 2018 in United States| Report Duplicate | Flag | PURGE

Akamai Software Engineer Algorithm - 0of 0 votes

AnswersGiven 2 sets of words. Find the words in 2nd set that begin with any word in the 1st set.

- interviewquestionsseeker September 07, 2018 in United States| Report Duplicate | Flag | PURGE

Akamai Software Engineer Algorithm - 0of 0 votes

AnswerLargest Sum Contiguous Subarray

- interviewquestionsseeker September 07, 2018 in United States| Report Duplicate | Flag | PURGE

Akamai Software Engineer Algorithm - 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

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

Open Chat in New Window