## Recent Interview Questions

- 4of 4 votes

AnswersYou are given a set of unique characters and a string.

- francisvm February 04, 2015 in United States

Find the smallest substring of the string containing all the characters in the set.

ex:

Set : [a, b, c]

String : "abbcbcba"

Result: "cba"| Report Duplicate | Flag | PURGE

Facebook Intern Algorithm - 2of 4 votes

AnswersInplace reverse a sentence

You given a sentence of english words and spaces between them.

Nothing crazy:

1) no double spaces

2) no empty words

3) no spaces at the ends of a sentence`void inplace_reverse(char* arr, int length) { // your solution }`

Example:

- Sergey January 17, 2015 in United States

input "I wish you a merry Christmas"

output "Christmas merry a you wish I"

Constrains: O(1) additional memory| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm - 2of 2 votes

AnswersFind first unique number in an unsorted array of 32 bit numbers without using hash tables or array of counters.

- xejgomi February 16, 2014 in United States| Report Duplicate | Flag | PURGE

Bloomberg LP Financial Software Developer Algorithm - 3of 5 votes

AnswersPrint all palindromes of size greater than equal to 3 of a given string. (DP)

- amnesiac February 15, 2014 in United States| Report Duplicate | Flag | PURGE

Epic Systems Software Engineer / Developer Algorithm - 6of 6 votes

AnswersWrite a function for retrieving the total number of substring palindromes.

- Andrew November 04, 2013 in United States

For example the input is 'abba' then the possible palindromes= a, b, b, a, bb, abba

So the result is 6.

Updated at 11/11/2013:

After the interview I got know that the O(n^3) solution is not enough to go to the next round. It would have been better to know before starting implementing the solution unnecessarily ...| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm - 10of 12 votes

AnswersGiven an equation in the form 2^i * 3^j * 5^k * 7^l where i,j,k,l >=0 are integers.write a program to generate numbers from that equation in sorted order efficiently.

- Rohit July 29, 2013 in United States

for example numbers from that equation will be in the order 2,3,5,6,7,8,9.....and so on..| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 5of 5 votes

AnswersGiven a array of integers , find 3 indexes i,j,k such that, i<j<k and a[i] < a[j] < a[k]. Best possible is a O(n) algorithm.

- kingKode October 26, 2012 in India| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 0of 0 votes

Answersx = x++ + ++y;

- Lively May 06, 2012 in United States

y = ++x + ++y;

what are the values of x,y after these are executed ?| Report Duplicate | Flag | PURGE

Cisco Systems Software Engineer / Developer C - 0of 0 votes

AnswersFind all the possible passwords, given the length of the password and that it is a well ordered number (159 is well-ordered as 1<5<9)

- S.A.M March 10, 2012 in United States| Report Duplicate | Flag | PURGE

Epic Systems Software Engineer / Developer Java - 1of 1 vote

Answersthere is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on..

- anonymous July 14, 2011 in United States

It looks something like this

1

2 3

4 5 6

every cup has capacity C. you pour L liters of water from top . when cup 1 gets filled , it overflows to cup 2,3 equally, and when they get filled , Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the cups and so on.

Now given C and M .Find the amount of water in ith cup.| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Dynamic Programming - 3of 3 votes

AnswersYou are given a dictionary, in the form of a file that contains one word per line. E.g.,

- audi March 14, 2013 in United States

abacus

deltoid

gaff

giraffe

microphone

reef

qar

You are also given a collection of letters. E.g., {a, e, f, f, g, i, r, q}.

The task is to find the longest word in the dictionary that can be spelled with the collection of

letters. For example, the correct answer for the example values above is “giraffe”. (Note that

“reef” is not a possible answer, because the set of letters contains only one “e”.)| Report Duplicate | Flag | PURGE

Google Algorithm - 4of 4 votes

AnswersGiven an array A of N integers, we draw N discs in a 2D plane such that the I-th disc is centered on (0,I) and has a radius of A[I]. We say that the J-th disc and K-th disc intersect if J ≠ K and J-th and K-th discs have at least one common point.

- adam2008 February 22, 2013 in United States

Write a function:

int number_of_disc_intersections(int A[], int N);

that, given an array A describing N discs as explained above, returns the number of pairs of intersecting discs. For example, given N=6 and:

A[0] = 1 A[1] = 5 A[2] = 2

A[3] = 1 A[4] = 4 A[5] = 0

intersecting discs appear in eleven pairs of elements:

0 and 1,

0 and 2,

0 and 4,

1 and 2,

1 and 3,

1 and 4,

1 and 5,

2 and 3,

2 and 4,

3 and 4,

4 and 5.

so the function should return 11.

The function should return −1 if the number of intersecting pairs exceeds 10,000,000.

Assume that:

N is an integer within the range [0..10,000,000];

each element of array A is an integer within the range [0..2147483647].

Complexity:

expected worst-case time complexity is O(N*log(N));

expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).

Elements of input arrays can be modified.| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer - 3of 3 votes

AnswersWrite a program to determine whether n/2 distintinctve pairs can be formed from given n integers where n is even and each pair's sum is divisible by given k. Numbers cannot be repeated in the pairs, that means only you can form total n/2 pairs.

- topjobsncr October 09, 2012 in India| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 0of 0 votes

AnswersGiven n arrays, find n number such that sum of their differences is minimum. For e.g. if there are three arrays

- A June 30, 2011

A = {4, 10, 15, 20}

B = {1, 13, 29}

C = {5, 14, 28}

find three numbers a, b, c such that |a-b| + |b-c| + |c-a| is minimum. Here the answer is a = 15, b = 13, and c = 14| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Algorithm - 1of 1 vote

AnswersYou are given a sorted list of distinct integers from 0 to 99, for instance [0, 1, 2, 50, 52, 75]. Your task is to produce a string that describes numbers missing from the list; in this case "3-49,51,53-74,76-99".

- Casper November 14, 2016 in United States

Examples:

[] “0-99”

[0] “1-99”

[3, 5] “0-2,4,6-99”| Report Duplicate | Flag | PURGE

Google Software Engineer Intern C++ - 0of 0 votes

AnswersYou are given an array, you have to replace each element of the array with product of the rest element. Example: {1,2,3}==> {6,3,2}

- neelabhsingh February 20, 2015 in India for Hyderabad| Report Duplicate | Flag | PURGE

Amazon SDE1 Algorithm - 1of 1 vote

AnswersGiven a string with multiple spaces write a function to in-place trim all spaces leaving a single space between words

- employee11 June 09, 2014 in Israel

e.g.

_ _ _ Hello _ _ _ World _ _ _

Hello _ World _ _ _ _ _ _ _ _ _| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 4of 4 votes

AnswersGiven an unordered array of positive integers, create an algorithm that makes sure no group of integers of size bigger than M have the same integers.

- Fred_Castro January 22, 2014 in United States

Input: 2,1,1,1,3,4,4,4,5 M = 2

Output: 2,1,1,3,1,4,4,5,4| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm - 2of 2 votes

AnswersHow to find in a binary tree, whether all leaves are at same level or not, and return a boolean value after identifying this.

- seth June 04, 2013 in India| Report Duplicate | Flag | PURGE

Amazon SDE1 Data Structures - 18of 22 votes

AnswersGiven a BST and a value x. Find two nodes in the tree whose sum is equal x. Additional space: O(height of the tree). It is not allowed to modify the tree

- pavel.em January 26, 2013 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 0of 0 votes

AnswersGiven an unsorted array, how to divide them into two equal arrays whose sum of difference is minimum.

- Psycho September 29, 2012 in United States

Can it be done in o(n)?| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Algorithm Morgan Stanley Java Developer Coding - 0of 0 votes

AnswersGiven an array of integers, find all combination of four elements in the array whose sum is equal to a given value X.

- sai September 04, 2012 in India

For example, if the given array is {10, 2, 3, 4, 5, 9, 7, 8} and X = 23, then your function should print “3 5 7 8″ (3 + 5 + 7 + 8 = 23).| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - 0of 0 votes

AnswersFind the kth smallest element in a sorted array

- neo April 28, 2012 in India| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer - 0of 0 votes

AnswersGiven a number,find the next higher number using the same digits in the number. Eg- 15432, Soln- 21345.

- Puzzle November 19, 2011 in United States| Report Duplicate | Flag | PURGE

Amazon Software Engineer in Test Software Engineer / Developer Algorithm - 0of 0 votes

AnswersGiven a array, find k increasing numbers whose summation will be maximum.

- Anonymous July 25, 2010

Array: 1,5,2,8,7,6,11

k=3

Answer: 5,8,11=24| Report Duplicate | Flag | PURGE

IBM Software Engineer / Developer - 3of 3 votes

AnswersGiven a length n, return the number of strings of length n that can be made up of the letters 'a', 'b', and 'c', where there can only be a maximum of 1 'b's and can only have up to two consecutive 'c's

- djway August 10, 2016 in United States for None

Example:

findStrings(3) returns 19

since the possible combinations are: aaa,aab,aac,aba,abc,aca,acb,baa,bac,bca,caa,cab,cac,cba,cbc,acc,bcc,cca,ccb

and the invalid combinations are:

abb,bab,bba,bbb,bbc,bcb,cbb,ccc| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 0of 0 votes

AnswersWrite a method that takes in a positive integer, return the number of 2s between 0 and the input number.

- J@sper November 26, 2015 in United States

If the input value given is 13, it should return 2 as the number 2 and 12 are between 0 and 13.

If the input value given is 21, it should return 3 as the number 2,12 and 20 are between 0 and 21.| Report Duplicate | Flag | PURGE

Amazon Jr. Software Engineer Java

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

Open Chat in New Window