## Algorithm Interview Questions

- 0of 0 votes
Lets there are n stores.

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.

- 0of 0 votes
Pascal Triangle Hockey Stick Identity?

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

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

- 0of 0 votes
Find 2nd duplicate in an array

- 0of 0 votes
Given 2 sets of words. Find the words in 2nd set that begin with any word in the 1st set.

- 0of 0 votes
Largest Sum Contiguous Subarray

- 0of 0 votes
Given 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:

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.

- 0of 0 votes
What is idempotence and why is it useful for API design? (~2-6

sentences)

- 0of 0 votes
Looking at this function, what bugs do you see or concerns do you have

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}}

- 0of 0 votes
What does this Javascript ES6 function do and how is it useful? If you

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

}

}}

- 0of 0 votes
You 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:`. - Free path/road # - Building B - Google bike Employee location - (x, y) - (1, 2) . . . . . # . . E . . # # # # # . # . B . . . . . . . . . B`

- -2of 2 votes
Join Illuminati Order For Rich, Wealth, Fame, Love, LUCK,+27639233909 .. Ghana Australia, Canada, Dubai, Germany, Hong kong, India, Kuwait, Malaysia, Singapore, New Zealand, Uae, Uk, Usa, OmanJohannesburg Lenasia Midrand Randburg Roodepoort Sandton Soweto Alberton Germiston Benoni Boksburg ,Brakpan Daveyton,Duduza ,edenvale ,germiston Impumelelo Isando Katlehong Kempton Park KwaThema Nigel Reiger Park Springs Tembisa Thokoza Tsakane Vosloorus Wattville Atteridgaeville Centurion Hammanskraal Join the multi billionaires great illuminate.in Johannesburg Lenasia Midrand Randburg Roodepoort Sandton Soweto Alberton Germiston Benoni Boksburg ,Brakpan Daveyton,Duduza ,edenvale ,germiston Impumelelo Isando Katlehong Kempton Park KwaThema Nigel Reiger Park Springs Tembisa Thokoza Tsakane Vosloorus Wattville Atteridgaeville Centurion Hammanskraal

WE ARE DYING BECAUSE OF OUR BAD LEADER,JOIN THE GREAT OCCULT TEMPLE OF BAPHOMENT BROTHERHOOD TO BE WEALTHY JOIN US WE GUARANTEE YOU SUCCESS,100% WEALTH,POWER,FAME WE ARE HERE FOR THE DESPERATE ONE’S, DON’T MISS THIS OPPORTUNITY IN SOUTH AFRICA+27639233909

JOIN US AND MAKE YOUR DREAMS COME TO PASS

JOIN THE BEST OCCULT WITHOUT ANY HUMAN SCARIFIES

WE WILL CONNECT YOU TO THE TOP TEN RICHEST MEN IN THE WORLD

WE WILL GIVE ALL IT TAKES TO BECOME A MAN

AFTER YOUR INITIATION THE LORD OF MONEY WILL VISIT YOU

(1) YOU MOST BE ABOVE 18YEARS

( 2)YOU MUST BE ABLE TO KEEP SECRET BE WARNED

FOR MORE INFORMATION: call JOIN OCCULT OF RICHES,POWER,FAME,SUCCESS AND MONEY CALL +27639233909

I understands when we face challenge we expect it solution, but must it be in spiritual means, this is common in Africa why? Africans do it looking why looking for husband, Wife, business success, before traveling, before eating, job interview, carrying out one duties etc. callJOIN OCCULT OF RICHES,POWER,FAME,SUCCESS AND MONEY CALL

WE ARE OUR BROTHER’S KEEPER. ONE FOR ALL. ALL FOR ONE

JOIN THE BAPHOMET BROTHERHOOD TO CHANGE YOUR LIFE FOR EVER. FOR MORE INFORMATION YOU CAN EMAIL:mapesalupita@gmail.com

2018 BAPHOMET brotherhood is currently going on celebrating years anniversary power by (lord Baphomet) giving out the sum of =N=10,000,000 each to the ten lucky winners in the club kindly contact the grand master JOIN OCCULT OF RICHES,POWER,FAME,SUCCESS AND MONEY CALL +27639233909

IF YOU NEED ANY ASSISTANT FINANCIALLY,JOB OFFERING,CONTRACT ,OIL SUPPLIED,PETROL CHEMICAL ENGINEER,OPPORTUNITY TO. WORK IN OIL COMPANY,EDUCATION ASSISTANTS FEEL FREE TO CONTACT THIS NUMBER IF YOU WISH JOIN THE BAPHOMET BROTHERHOOD OCCULT TEMPLE THAT GIVE YOU ALL YOU WANT IN LIFE WE ARE THE BEST OCCULT GROUP IN AFRICA JOIN US WE GUARANTEE YOU WEALTH,FAME,POWER,SUCCESS IN LIFE

“If your only goal is to become rich, you’ll never achieve it,” says, the lord Ozumba.

His point was simple: when the only thing you care about is making money, no amount of money is ever enough. What you have always pales in comparison to what you don’t have and could have.

That’s why true success always involves a lot more than money… but even so, while we all define success differently (as well we should), most of us do factor some degree of wealth into our success equations.

So how do you become super rich? First embrace one fact: you’ll never get there on salary alone. join us in the word we will show you the secret of money and wealth call+27639233909

HAVE YOU BEEN SEARCHING FOR A WAY TO JOIN A SECRET OCCULT AND BECOME SUPPER RICH AND ALSO BE NOTIFY BY EVERYONE AROUND YOU,OR IF YOU ARE SEEKING FOR PROTECTION, JOIN THE GREAT BAPHOMENT BROTHERHOOD AND ALL YOUR HEARTH DESIRES SHALL BE GRANTED. CALLUS WITH +27639233909 OR YOU CAN ALSO

Today many people wish to become rich and famous and look for easy ways. Learn why so many folks wish to join the BAPHOMENT brotherhood in South Africa

There are thousands of secret organizations in the whole world. Some of these organizations are opened others are private. For many years, since fifth century and until now, there is a single most well-known organization that has always been absolutely closed. It is called BAPHOMENT. For long time information about how to join BAPHOMENT brotherhood in South Africa or any other country was absolutely secret. People all over the world wanted to join this organization but only the best of the best were accepted. Since that time, a lot have changed. The BAPHOMENT brotherhood is still positioned as one of the most powerful organization and still many people want to join it.

“Never give up on a dream just because of the time it will take to accomplish it. The time will pass anyway. ”

JOIN THE GREAT Baphomet BROTHERHOOD FOR FAME, POWER,WEALTH and PROTECTION.

This life, nobody was born to suffer but out of greed, stupidity

and self contentedness nobody wants to help that is the reason we THE Baphoment GREAT BROTHERHOOD has decided to give back hope to the hopeless and becoming a member of this fraternity absolutely free no charges no human sacrifice. for more information about THE GREATBAPHOMENT BROTHERHOOD just contact us on: +27639233909

Email us with : mapesalupita@gmail.com

- 0of 0 votes
...

- 0of 0 votes
For 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.

- 0of 2 votes
What is the best way to generate first N primes? (not primes up to N but first N primes)

- 0of 0 votes
**Game of Bits**

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.

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

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"

- 1of 1 vote
I don't remember perfectly the question, but it was like this

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.

- 2of 2 votes
Given 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.

- 0of 0 votes
Design and implement a interest matching algo, to match people according to their interests in a particular area.

Suggest a score based on their interests. And rank matchings accordingly.

- 0of 0 votes
In 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-

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.

- 0of 0 votes
set 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.

- 1of 1 vote
Given a map represented as a 2d array with only 0’s and 1’s. An island is a group of connected 1’s. Find out how many distinct islands(can be rotated).

eg:

1 1 0 0

1 0 0 0

0 0 0 1

0 0 1 1

return 2.

- 0of 0 votes
Given 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.

Water can flow from top to bottom, diagonally, horizontally as well. Only flowing from bottom to top is not possible.

- 0of 0 votes
Given 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).

- 0of 0 votes
water capacity in a histogram

what is the capacity if an array value becomes 0 - which will make the water to flow off the histogram

- 0of 0 votes
Reverse a linked list

- 0of 0 votes
Find Duplicate number from a huge amount of data which cannot fit in the memory.

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