## Recent Interview Questions

- 0of 0 votes

AnswersInput is a matrix of size n x m of 0s and 1s.

- coder August 31, 2011

eg:

1 0 0 1

0 0 1 0

0 0 0 0

If a location has 1; make all the elements of that row and column = 1. eg

1 1 1 1

1 1 1 1

1 0 1 1

Solution should be with Time complexity = O(n*m) and O(1) extra space| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Algorithm - 1of 1 vote

AnswersAn array of size n+1 has integers only from 1 to n. The integers 1 to n can be present 0 or more times in the array. Find the first repeating element in the array.

- AL March 27, 2011

Restrictions: O(n) algo required. Cannot use extra space(not even O(1)).| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Arrays - 0of 0 votes

AnswersThere is a security keypad at the entrance of a building. It has 9 numbers 1 - 9 in a 3x3 matrix format.

- Anonymous May 25, 2010

1 2 3

4 5 6

7 8 9

The security has decided to allow one digit error for a person but that digit should be horizontal or vertical. Example: for 5 the user is allowed to enter 2, 4, 6, 8 or for 4 the user is allowed to enter 1, 5, 7. IF the security code to enter is 1478 and if the user enters 1178 he should be allowed. Write a function to take security code from the user and print out if he should be allowed or not| Report Duplicate | Flag | PURGE

Epic Systems Software Engineer / Developer Data Structures - 1of 1 vote

AnswersGiven an array, find the first repeated number.

- Satish October 22, 2008| Report Duplicate | Flag | PURGE

Microsoft Software Engineer in Test Arrays - 0of 0 votes

Answerstwo link lists starts from head1 and head2 but their some nodes are common as shown below so they end at the same node

- Ravi Kant Pandey March 28, 2007

like

a-b-c-d-e-f-

g-h-i

x-y-z-w-

write an algo to find the first commom element of the list ie g.| Report Duplicate | Flag | PURGE

Adobe Software Engineer / Developer Algorithm - 22of 22 votes

AnswersImplement binary addition of two strings.

- fruktoed August 14, 2020 in UK, London

For example "101101" and "111101" equal "1101010"

You cannot use any type conversion, operate only with strings.| Report Duplicate | Flag | PURGE

Facebook Android Engineer Algorithm - 0of 0 votes

AnswersThere are three threads in a process.

- jim.shan.JS May 15, 2015 in United States

The first thread prints 1 1 1 …, the second one prints 2 2 2 …, and the third one prints 3 3 3 … endlessly.

How do you schedule these three threads in order to print 1 2 3 1 2 3 …?| Report Duplicate | Flag | PURGE

Salesforce Software Engineer Threads - 3of 3 votes

AnswersThere are N pots. Every pots have some water in it. They may be partially filled. So there is a Overflow Number 0 associated with every pot which tell how many minimum stone pieces are require for that pot to overflow. So if for a pot 0-value is 5 it means minimum 5 stone pieces should be put in that pot to make it overflow. Initially a crow watched those pots and by seeing the water level he anticipated 0-value correctly for every pot ( that is he knew 01 to On). But when he came back in evening he found that every pot is painted from outside and he is not able to know which pot has what 0-value. Crow wants some K pots to overflow so that he can serve his child appropriately. For overflow of pots he need to search for stone in forest( assume that every stone has same size). He wants to use minimum number of stones required to overflow K pots. But only he know the 0-value of pots he doesn't know now which pot has what 0-value. So the task is that in what minimum number of stones he can make K pots overflow in worst case.

- veeru April 29, 2015 in India for Development

Input/Output Specifications Input Specification: 1) A array 0 corresponding to 0-value of N pots {01, 02, On} 2) Number of pots 3) K -value ( number of pots which the crow wants to overflow}

Output Specification: Minimum number of stones required to make K pots overflow in worst case. Or -1 if input is invalid

Example: Let say there are two pots pot 1 has 0 value of 5 , 01= 5 pot 2 has 0 value of 58, 02= 58 Let say crow wants to make one of the pot to overflow. If he know which pot has what 0-value he would simple search for 5 stones and put then in pot 1 to make it overflow. But in real case he doesn't know which pot has what 0-value so just 5 stones may not always work. However he does know that one pot has 0-value S and other has 58. So even in worst case he can make one of the pot overflow just by using 10 stones. He would put 5 stones in one pot if it doesn't overflow he would try the remaining 5 in the other pot which would definitely overflow because one of the pot has 0-value of 5. So the answer for above question is minimum 10 stones even in worst case. Input : Input 1= {5,58} Input 2= 2 Input 3= 1 Output : 10| Report Duplicate | Flag | PURGE

Amazon Software Engineer - 3of 3 votes

AnswersGiven a dictionary that contains mapping of employee and his/her manager like this

- enok April 09, 2015 in United States

Dictionary<string, string> employees = new Dictionary<string, string>()

{

{ "A","C" },

{ "B","C" },

{ "C","F" },

{ "D","E" },

{ "E","F" },

{ "F","F" }

};

Write a function to get no of employees under each manager in the hierarchy not just their direct reports.

In the above dictionary the root node/ceo is listed as reporting to himself.

Output should be a Dictionary<string,int> that contains this

A - 0

B - 0

C - 2

D - 0

E - 1

F - 5| Report Duplicate | Flag | PURGE

Microsoft SDE1 Algorithm - 2of 2 votes

AnswersInput: A string equation that contains numbers, '+' and '*'

- huji February 23, 2015 in Israel

Output: Result as int.

For example:

Input: 3*5+8 (as String)

Output: 23 (as int)| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 0of 0 votes

AnswersArray of size (n-m) with numbers from 1..n with m of them missing. Find one all of the missing numbers in O(log). Array is sorted.

- suu December 05, 2014 in United States

Example:

n = 8

arr = [1,2,4,5,6,8]

m=2

Result has to be a set {3, 7}.| Report Duplicate | Flag | PURGE

Facebook SDE1 - 3of 5 votes

AnswersGiven a set of busy time intervals of two people as in a calendar, find the free time intervals of both the people so as to arrange a new meeting

- Phoenix December 02, 2014 in United States

input: increasing sequence of pair of numbers

per1: (1,5) (10, 14) (19,20) (27,30)

per2: (3,5) (12,15) (18, 21) (23, 24)

ouput: (6,9) (16,17) (22,22) (25,26)| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 0of 0 votes

AnswersYou are given an array of non-negative integers (0, 1, 2 etc). The value in each element represents the number of hops you may take to the next destination. Write a function that determines when you start from the first element whether you will be able to reach the last element of the array.

- Anon80 December 02, 2014 in United States

if a value is 3, you can take either 0, 1, 2 or 3 hops.

For eg: for the array with elements 1, 2, 0, 1, 0, 1, any route you take from the first element, you will not be able to reach the last element.| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer - 1of 1 vote

AnswersGiven a array of positive integers, find all possible triangle triplets that can be formed from this array.

- Aspire November 25, 2014 in United States

eg: 9 8 10 7

ans: 9 8 10, 9 8 7, 9 10 7, 7 8 10

Note : array not sorted, there is no limit on the array length| Report Duplicate | Flag | PURGE

Linkedin SDE1 Algorithm - 9of 11 votes

AnswersGiven a number N, write a program that returns all possible combinations of numbers that add up to N, as lists. (Exclude the N+0=N)

- ootah November 14, 2013 in United States

For example, if N=4 return {{1,1,1,1},{1,1,2},{2,2},{1,3}}| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm - 7of 9 votes

AnswersImagine an alphabet of words. Example:

- hani.amr June 30, 2013 in United States

a ==> 1

b ==> 2

c ==> 3

.

z ==> 26

ab ==> 27

ac ==> 28

.

az ==> 51

bc ==> 52

and so on.

Such that the sequence of characters need to be in ascending order only (ab is valid but ba is not). Given any word print its index if valid and 0 if not.

Input Output

ab 27

ba 0

aez 441

Note: Brute-force is not allowed.| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Algorithm - 0of 0 votes

AnswersImplement a set that supports insert, remove and getRandomElement() operations.

- ak February 21, 2013 in India| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Data Structures - 1of 1 vote

AnswersIf you're given a list of countries and its corresponding population, write a function that will return a random country but the higher the population of the country, the more likely it is to be picked at random.

- Curious September 05, 2012 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 0of 0 votes

AnswersN*N matrix. contains only 0's and 1's.

- kb August 13, 2012 in India

every row is sorted in descending order.

find row containing maximum no of 1's. Efficient soln reqd.| Report Duplicate | Flag | PURGE

Adobe Amazon Algorithm Coding - 0of 0 votes

AnswersYou are given a string. You need to find the longest substring with unique characters in O(n) time

- DashDash May 26, 2012 in India| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - -2of 2 votes

AnswersFind kth largest of sum of elements in 2 array .

- Anonymous January 14, 2011| Report Duplicate | Flag | PURGE

Google Algorithm - 1of 5 votes

AnswersDivide a list of numbers into group of consecutive numbers but their original order should be preserved?

- rhine November 23, 2008

e.g.

8,2,4,7,1,0,3,6

2,4,1,0,3 and 8,7,6

obviously in shortest time and space.| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm - 0of 0 votes

AnswersHow do you implement three stacks in a single array as efficiently as possible?

- Ravi kishore May 03, 2007| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Algorithm - 0of 0 votes

AnswersGiven an array of integers:

- xjohnwu April 07, 2017 in UK

1. rearrange the array such that all non-zero members appear on the left of the array (order is not important)

2. return the number of non-zero members

e.g. [1,2,0,5,3,0,4,0] => [1,2,5,3,4,0,0,0] and return 5. The non-zero array members can be in any order.| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm - 3of 3 votes

AnswersGiven: sorted array of integers

- 123georgedavid September 21, 2016 in United States

Return: sorted array of squares of those integers

Ex: [1,3,5] -> [1,9,25]

Integers can be negative.| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 2of 2 votes

AnswersNumber list compressing.

- byPaco September 15, 2015 in United States

Given an sorted array. Input: sorted number list

1, 2, 3,10, 25, 26, 30, 31, 32, 33

Output: find consecutive segments

print: 1-3, 10, 25-26, 30-33| Report Duplicate | Flag | PURGE

Google iOS Developer - 0of 0 votes

AnswersWrite a function

- psuedo April 10, 2015 in India

bool fancy_shuffle(char* s);

which rearranges characters in the string given as input, in such a way that no same character occurs twice in a row (that is, next to each other).

If such rearrangement is not possible, the function should return false.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm

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