## Recent Interview Questions

- 0of 0 votes

AnswersGiven a random number generator say r(5) generates number between 1-5 uniformly at random , use it to in r(7) which should generate a random number between 1-7 uniformly at random.

- geekonomics January 19, 2012 in United States| Report Duplicate | Flag | PURGE

A9 Software Engineer / Developer Brain Teasers Amazon - 4of 4 votes

AnswersGiven a Start Node and an End Node in a graph report if they are “necessarily connected”. This means that all paths from the start node lead to the end node. Report true all paths from start node lead to end node and false if at least one path does not lead to the end node. This is a directed graph which can have cycles

- nikki December 31, 2018 in United States

Does anyone know how to solve this? I had it in my interview at Google in CA and I still cant solve it| Report Duplicate | Flag | PURGE

Google SDE1 Algorithm - 11of 11 votes

AnswersThere are at most eight servers in a data center. Each server has got a capacity/memory limit. There can be at most 8 tasks that need to be scheduled on those servers. Each task requires certain capacity/memory to run, and each server can handle multiple tasks as long as the capacity limit is not hit. Write a program to see if all of the given tasks can be scheduled or not on the servers?

- CodeKaur August 04, 2014 in United States

Ex:

Servers capacity limits: 8, 16, 8, 32

Tasks capacity needs: 18, 4, 8, 4, 6, 6, 8, 8

For this example, the program should say 'true'.

Ex2:

Server capacity limits: 1, 3

Task capacity needs: 4

For this example, program should return false.

Got some idea that this needs to be solved using dynamic programming concept, but could not figure out exact solution.| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 0of 0 votes

AnswersMaximum value Continuous Subsequence:

- pirate July 25, 2013 in United States

Given array A[n] find continuous subsequence a[i]..a[j] for which sum of elements in the subsequence is maximum.

Ex: {-2, 11, -4, 13, -5, -2} --> 11 - 4 +13 = 20

{1, -3, 4, -2, -1, 6} --> 4 -2 -1 +6 = 7

Time complexity should O(nlogn)| Report Duplicate | Flag | PURGE

Yahoo Microsoft Linkedin Software Engineer / Developer Algorithm Arrays - 3of 3 votes

AnswersQ1.- Written exam (Amazon, Bangalore)

- Nitin Gupta May 12, 2012 in India

Given a singly link list and a number 'K', swap the Kth node from the start with the Kth node from the last. Check all the edge cases.

Sample Input: 1->2->3->4->5->6->7->8 and K = 3

Sample Output : 1->2->6->4->5->3->7->8

Sample Input: 1->2->3->4->5->6->7->8 and K = 10

Sample Output: print error "LIST IS OF LESSER SIZE".| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm C C# C++ Coding Data Structures Java Linked Lists - 2of 4 votes

Answers/*

- friendlytechs June 25, 2014 in United States

Write an algorithm that brings all nonzero elements to the left of the array, and returns the number of nonzero elements.

Example input: [ 1, 0, 2, 0, 0, 3, 4 ]

Example output: 4

[1, 4, 2, 3, 0, 0, 0]

* The algorithm should operate in place, i.e. shouldn't create a new array.

* The order of nonzero elements does not matter

*/| Report Duplicate | Flag | PURGE

Facebook Android test engineer - 3of 3 votes

AnswersGiving a string and an string dictionary, find the longest string in dictionary which can formed by deleting some characters of the giving string.

- IKnowThings January 28, 2017 in United States

eg:S = abpcplea, Dict = {ale, apple, monkey, plea}, the return "apple"

I was thinking of the following approach,

Build a Trie for all words in the Dict - O( n * k) where k is the longest string in the dict

For each character c, in S check if there is a word in Trie that starts with it and has the letters that appear in S after c. We can short circuit based on remaining characters and the length of longest string found so far.

This should take O( N * k) where N is length of S.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 11of 13 votes

AnswersGiven s string, Find max size of a sub-string, in which no duplicate chars present.

- sanjay05iitr November 10, 2013 in India for Cyllas Experience| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 2of 6 votes

AnswersConsider the statement

- gjp February 24, 2014 in United States

result = a ? b : c;

Implement the above statement without using any conditional statements.| Report Duplicate | Flag | PURGE

NVIDIA Software Engineer Intern Bit Manipulation C - 2of 2 votes

AnswersMcDonald’s sells Chicken McNuggets in packages of 6, 9 or 20 McNuggets. Thus, it is possible, for example, to buy exactly 15 McNuggets (with one package of 6 and a second package of 9), but it is not possible to buy exactly 16 McNuggets, since no non- negative integer combination of 6's, 9's and 20's add up to 16. To determine if it is possible to buy exactly n McNuggets, one has to find non-negative integer values of a, b, and c such that

- nishakothari62 November 03, 2012 in United States

6a+9b+20c=n

Write a function, called McNuggets that takes one argument, n, and returns True if it is possible to buy a combination of 6, 9 and 20 pack units such that the total number of McNuggets equals n, and otherwise returns False. Hint: use a guess and check approach.| Report Duplicate | Flag | PURGE

Facebook Developer Program Engineer Python - 0of 0 votes

AnswersString Reduction

- sf engineer February 20, 2012 in United States

Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can result by applying this operation repeatedly?

Input:

The first line contains the number of test cases T. T test cases follow. Each case contains the string you start with.

Output:

Output T lines, one for each test case containing the smallest length of the resultant string after applying the operations optimally.

Constraints:

1 <= T <= 100

The string will have at most 100 characters.

Sample Input:

3

cab

bcab

ccccc

Sample Output:

2

1

5

Explanation:

For the first case, you can either get cab -> cc or cab -> bb, resulting in a string of length 2.

For the second case, one optimal solution is: bcab -> aab -> ac -> b. No more operations can be applied and the resultant string has length 1.

For the third case, no operations can be performed and so the answer is 5.| Report Duplicate | Flag | PURGE

Facebook Amazon Software Engineer / Developer Algorithm - 0of 0 votes

AnswersThere are two arrays.

- lipun4u November 22, 2011 in India

int arr1[5] = { 3, 5, 2, 5, 2}

int arr2[5] = { 2, 3, 5, 5, 2}

The arrays will be called similar if they contain same number of elements equally.

Write the pseudo code to check this ?

I was not allowed to use sorting and hashtable.| Report Duplicate | Flag | PURGE

Goldman Sachs Software Engineer / Developer Algorithm - 3of 3 votes

AnswersGiven a circular single linked list.Write a program that deletes every kth node until only one node is left.

- Aashish August 01, 2012 in India

After kth node is deleted, start the procedure from (k+1)th node.

e.g.list is 1->2->3->4->5->1

k=3

1. You are at 1, delete 3.

List is: 1->2->4->5->1

2. You are at 4, delete 1

List is: 2->4->5->2

3. You are at 2,delete 5

List is: 2->4->2

4. You are at 2, delete 2

List is: 4

Return 4.

How efficient you can do it?| Report Duplicate | Flag | PURGE

Amazon Google Software Engineer / Developer Algorithm - 1of 1 vote

AnswersYou are given two numbers in the form of linked list.Add them without reversing the linked lists. linked lists can be of any length.

- manjunath426jc December 26, 2011 in India

Ex:123 1->2->3

10234 1->0->2->3->4

ans: 10357 1->0->3->5->7| Report Duplicate | Flag | PURGE

Amazon Qualcomm Software Engineer / Developer Linked Lists - 1of 1 vote

AnswersConsider a series in which 8 teams are participating. each team plays twice with all other teams. 4 of them will go to the semi final.How many matches should a team win, so that it will ensure that it will go to semi finals.?

- putta.sreenivas May 11, 2011| Report Duplicate | Flag | PURGE

Amazon Google Developer Program Engineer Software Engineer / Developer Algorithm Brain Teasers - 6of 6 votes

AnswersThe input is a sequence x1,x2,...,xn of integers in an arbitrary order, and another sequence

- Coder April 17, 2014 in United States

a1,a2,..,an of distinct integers from 1 to n (namely a1,a2,...,an is a permutation of

1, 2,..., n). Both sequences are given as arrays. Design an 0(n logn) algorithm to order

the first sequence according to the order imposed by the permutation. In other words, for

each i, Xi should appear in the position given in ai. For example, if x = 17, 5, 1,9, and a =

3, 2, 4, 1, then the outcome should be x = 9, 5, 17, 1. The algorithm should be in-place, so

you cannot use an additional array.| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Arrays - 11of 11 votes

AnswersGiven a sequence of non-negative integers find a subsequence of length 3 having maximum product with the numbers of the subsequence being in ascending order.

- Bhavi Jagwani April 06, 2013 in India

Example:

Input: 6 7 8 1 2 3 9 10

Ouput: 8 9 10| Report Duplicate | Flag | PURGE

Amazon - 1of 1 vote

AnswersWith a linked list data structure, find if a given string is palindrome or not.

- sathish.leo May 26, 2012 in United States| Report Duplicate | Flag | PURGE

Expedia Amazon Software Engineer / Developer Linked Lists - 2of 4 votes

AnswersGiven a sequence of numbers A(1) ..A(n), find the continuous subsequenceA(i)..A(j) for which the sum of elements is maximum.

- pirate July 28, 2013 in India

condition: we should not select two contiguous numbers| Report Duplicate | Flag | PURGE

Yahoo Facebook Software Engineer / Developer Algorithm - 0of 0 votes

Answersgiven 2 unsorted integer arrays a and b of equal size. Determine if b is a permutation of a. Can this be done in O(n) time and O(1) space ?

- pavel.em May 16, 2012 in United States| Report Duplicate | Flag | PURGE

Microsoft - 0of 0 votes

AnswersCompress a given string "aabbbccc" to "a2b3c3"

- john January 22, 2011

constraint: inplace compression, no extra space to be used

assumption : output size will not exceed input size.. ex input:"abb" -> "a1b2" buffer overflow.. such inputs will not be given.| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - 3of 3 votes

AnswersGiven a binary search tree (BST), write a mehtod that will convert this BST into a doubly linked list that is sorted (ascending or descending order) and returns the first element in this list. You may assume you are given following Node class:

`public class Node { public Node left, right; public String val; }`

Example: The following BST

- autoboli January 06, 2015 in United States

G

/ \

A T

can be converted into a list

A = G = T

Do it in place! Hnce the memory complexity of your algorithm shoul be O(1).| Report Duplicate | Flag | PURGE

Google Algorithm - 0of 0 votes

Answers49 race cars and no two have the same speed. Now give you 7 tracks with equal length to find the 25th fastest car. At least how many races are needed.(no time recorder)

- Hai.Vincent October 14, 2010| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Brain Teasers - 2of 4 votes

AnswersA string contains a-z, A-Z and spaces. Sort the string so that all lower cases are at the beginning, spaces in the middle and upper cases at the end. Original order among lower and upper cases needs to remain the same. For example: a cBd LkmY becomes ackm BLY. Is there a way in O(n) without extra space?

- chad August 13, 2015 in United States| Report Duplicate | Flag | PURGE

Amazon Software Developer Algorithm Arrays - 9of 9 votes

AnswersGiven an array of integers, sort the array into a wave like array, namely

- Zen April 22, 2014 in United States

a1 >= a2 <= a3 >= a4 <= a5.....| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 0of 0 votes

AnswersYou have given a positive number you have to find a number which is bigger than that by using same digits available in the number .

- Nitin September 19, 2011 in India

Example :-

You have given a number 7585 , your output should be 7855 .| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - 9of 9 votes

AnswersGiven a string (1-d array) , find if there is any sub-sequence that repeats itself.

- for.anonymous.usa October 22, 2014 in United States

Here, sub-sequence can be a non-contiguous pattern, with the same relative order.

Eg:

1. abab <------yes, ab is repeated

2. abba <---- No, a and b follow different order

3. acbdaghfb <-------- yes there is a followed by b at two places

4. abcdacb <----- yes a followed by b twice

The above should be applicable to ANY TWO (or every two) characters in the string and optimum over time.

In the sense, it should be checked for every pair of characters in the string.| Report Duplicate | Flag | PURGE

Google Software Engineer Intern Algorithm Brain Teasers C C++ Coding Data Structures Dynamic Programming Problem Solving String Manipulation - 3of 11 votes

AnswersGiven a binary representation of an integer say 15 as 1111, find the maximum longest continous sequence of 0s. The twist is it needs to be done in log N. I could think of O(N) solution. but couldn't go for log(N).

- TapeRecordia October 24, 2013 in United States

For example. 10000101

the answer should be 4, because there are 4 continouos zeroes.| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm

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

Open Chat in New Window