## Recent Interview Questions

- 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 - 8of 10 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 - 0of 0 votes

AnswersGiven you an array of 100 Elements with one number missing, how will you find the missing number?

- radibioinfo July 25, 2013 in United States

Array 1 to 100 with 55 missing.| Report Duplicate | Flag | PURGE

Amazon Quality Assurance Engineer Arrays - 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 - -8of 8 votes

Answerssort the array so that the odd number in front of the even number and their relative order doesn't change in Time O(n) and Space O(1). I believe quickselect can do this, but it will change the relative order of the input.

- Guy February 01, 2014 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 7of 7 votes

AnswersGiven a regular expression with characters a-z, ' * ', ' . '

- kevin October 13, 2013 in United States

the task was to find if that string could match another string with characters from: a-z

where ' * ' can delete the character before it, and ' . ' could match whatever character. ' * ' always appear after a a-z character.

Example:

isMatch("a*", "") = true;

isMatch(".", "") = false;

isMatch("ab*", "a") = true;

isMatch("a.", "ab") = true;

isMatch("a", "a") = true;| Report Duplicate | Flag | PURGE

Facebook Software Engineer Intern Algorithm - 1of 3 votes

AnswersReverse a string without using any temporary variable.

- rasmiranjanbabu August 31, 2013 in India

Suppose {{char str[] = "Hello"; then str[] = "olleH";}}}.

I told him we can "shift H to o then o to H", similarly so on. But could able to write the code.| Report Duplicate | Flag | PURGE

HCL Software Engineer / Developer C - 3of 5 votes

AnswersA string is called sstring if it consists of lowercase english letters and no two of its consecutive characters are the same.

- priteshpathak15 July 29, 2013 in India

You are given string s of length n. Calculate the number of sstrings of length that are not lexicographically greater than s.

Input format

The only line of input contains the string s. It's length is not greater than 100.

All characters of input are lowercase english letters.

Output format:

Print the answer of test modulo 1009 to the only line of output.

Sample input:

bcd

Sample output:

653| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Front-end Software Engineer Algorithm - 0of 0 votes

AnswersGiven a sorted integer array and a number, find the start and end indexes of the number in the array.

- bvinay84 July 11, 2013 in United States

Ex1: Array = {0,0,2,3,3,3,3,4,7,7,9} and Number = 3 --> Output = {3,6}

Ex2: Array = {0,0,2,3,3,3,3,4,7,7,9} and Number = 5 --> Output = {-1,-1}

Complexity should be less than O(n)| Report Duplicate | Flag | PURGE

Linkedin Software Engineer in Test Algorithm

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

Open Chat in New Window