## Recent Interview Questions

- 4of 4 votes

AnswersRearrange characters in a string so that no character repeats twice.

- pcinterview October 10, 2015 in United States

Input: aaabc

Output: abaca

Input: aa

Output: No valid output

Input: aaaabc

Output: No valid output| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 8of 8 votes

AnswersYou are given a list of n float numbers x_1, x_2, x_3, ... x_n, where x_i > 0.

- emb September 04, 2015 in United States

A traveler starts at point (0, 0) and moves x_1 metres to the north, then x_2 metres to the west, x_3 to the south, x_4 to the east and so on (after each move his direction changes counter-clockwise)

Write an single-pass algorithm that uses O(1) memory to determine, if the travelers path crosses itself, or not (i.e. if it's self-intersecting)

e.g.

2 1 1 2 -> crosses

1 2 3 4 -> doesn't cross| Report Duplicate | Flag | PURGE

Google Software Developer Algorithm - 1of 1 vote

AnswersInteger Array Ques:

- cdude September 01, 2015 in United States

Given an integer array of variable length like so [9, 8, 8, 3] where each item in array could be 0 to 9, write a function that would take would interpret the array [9, 8, 8, 3] as a number 9883 and increment it by 1. The return of the function would be an integer array containing the addition like so [9,8,8,4]. No zeros in the first position like [0,1,2,3]. I initially suggested a possible solution of process to convert the integer array to String then convert to Integer or Long and then do the addition of 1 and then convert it back to integer array. That is not allowed when the interviewer change the ques. to not allow that.| Report Duplicate | Flag | PURGE

Google Android Engineer Arrays - 2of 2 votes

AnswersWrite program for the following case

- APV July 25, 2015 in India for Amazon Wireless

Reverse string (string is stored in an array)

Input:- "This is an example"

Output:-sihT si na elpmaxe| Report Duplicate | Flag | PURGE

Amazon Quality Assurance Engineer String Manipulation - 7of 7 votes

AnswersYou are given a list of word. Find if two words can be joined to-gather to form a palindrome. eg Consider a list {bat, tab, cat} Then bat and tab can be joined to gather to form a palindrome.

- um01 May 14, 2015 in United States

Expecting a O(nk) solution where n = number of works and k is length

There can be multiple pairs| Report Duplicate | Flag | PURGE

Google SDE1 Algorithm - 0of 0 votes

AnswersYou are given a positive integer number N. Return the minimum number K, such that N can be represented as K integer squares.

- Anonymous January 27, 2015 in Israel

Examples:

9 --> 1 (9 = 3^2)

8 --> 2 (8 = 4^2 + 4^2)

15 --> 4 (15 = 3^2 + 2^2 + 1^2 + 1^2)

First reach a solution without any assumptions, then you can improve it using this mathematical lemma: For any positive integer N, there is at least one representation of N as 4 or less squares.| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 4of 4 votes

AnswersPrint combinations of strings from List of List of String

- mohrmanla October 23, 2014 in United States

Example input: [[quick, slow], [brown, red], [fox, dog]]

Output:

quick brown fox

quick brown dog

quick red fox

quick red dog

slow brown fox

slow brown dog

slow red fox

slow red dog| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer - 5of 7 votes

AnswersImplement below function.

int getRandom(int N, int K[])

Constraints:

->K is sorted and contains elements in range [0,N)

->Output should be a random number between [0,N) excuding elements from K

->probability of generated number should be 1/(N-K.length) and not 1/N

-->int uniform(int N) is given which returns random number [0,N) with 1/N probability for each number.

->No more than O(1) memory

->No more than O(N) time

Below is my solution but it uses O(N) space.

- G10 November 01, 2013 in United States`public int randomNumber(int N, int[] K) { // K is sorted //assumed size of K is less than N int remains[] = new int[N-K.length]; //i is index [0,N-1], j is an index of K, k is an index of remainings //Fill remaining array for (int i=0,j=0,k=0;i<N;i++){ if (i!=K[j]){ remainings[k++]=i; }else{ j++; } } int index = uniform(remainings.length); return remainings[index]; } Time complexity: O(N) Space Complexity: O(N)`

| Report Duplicate | Flag | PURGE

Google SDE1 Algorithm - 0of 2 votes

Answers###Print numbers between 45 to 4578 without repeating digits.###

- Anonymous September 24, 2013 in India

Ex: 45-ALLOWED;55(repeatng digits)(-NOT ALLOWED. Frnd tld ths 2 me.he tried diff concepts but interviewer wanted an OPTIMAL ONE..LETS C WHO WRITE THIS WITH SIMPLE LOGIC..| Report Duplicate | Flag | PURGE

Amazon Software Engineer in Test - 0of 0 votes

AnswersAn operation "swap" means removing an element from the array and appending it at the back of the same array. Find the minimum number of "swaps" needed to sort that array.

- Anirban October 27, 2012 in India

Eg :- 3124

Output: 2 (3124->1243->1234)

How to do it less than O(n^2) ?| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - 2of 2 votes

AnswersYou are given an array of n elements [1,2,....n]. For example {3,2,1,6,7,4,5}.

- Biswajit Sinha October 26, 2012 in India

Now we create a signature of this array by comparing every consecutive pir of elements. If they increase, write I else write D. For example for the above array, the signature would be "DDIIDI". The signature thus has a length of N-1. Now the question is given a signature, compute the lexicographically smallest permutation of [1,2,....n]. Write the below function in language of your choice.

vector* FindPermute(const string& signature);| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm - 1of 1 vote

AnswersGiven an array with positive, negative and zeros, arrange the given array such that negatives are on left, zeros in the middle and positives on the right.

- babbupandey August 20, 2012 in United States| Report Duplicate | Flag | PURGE

Microsoft Software Engineer in Test Algorithm Arrays - 0of 0 votes

AnswersFind the longest

- grave August 05, 2012 in India

subarray which consists of numbers that can be arranged in a continuous sequence.

For ex- {4,5,1,5,7,6,8,4,1}

output-{5,7,6,8,4}.Find the longest.| Report Duplicate | Flag | PURGE

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

Answersthree points are randomly chosen on a circle.what the probability that

- David August 02, 2011

1.triangle formed is right angled triangle.

2.triangle formed is acute angled triangle.

3.triangle formed is obtuse angled triangle.| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Math & Computation - 0of 0 votes

AnswersGiven a input string find the longest substring which appears more than once in the string?

- Tubs July 20, 2010| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Algorithm - 0of 0 votes

AnswersGiven an array of integers(both positive and negative) divide the array into two parts(sub-arrays) such that the difference between the sum of elements in each array is minimum????

- Anonymous December 24, 2009| Report Duplicate | Flag | PURGE

Google Development Support Engineer Algorithm - 0of 0 votes

AnswersYou have three baskets. Basket # has apples,Basket # 2 has oranges, and Basket #3 has oranges and apples.

- Junior Ranking July 10, 2007

THe baskets are mislabled.After how many tries will you be able to figure out which baskets have the correct items.| Report Duplicate | Flag | PURGE

Amazon Kalido Software Engineer / Developer Brain Teasers - 5of 5 votes

AnswersFind whether string S is periodic.

- aonecoding4 March 01, 2019 in United States

Periodic indicates S = nP.

e.g.

S = "ababab", then n = 3, and P = "ab"

S = "xxxxxx", then n = 1, and P = "x"

S = "aabbaaabba", then n = 2, and P = "aabba"

Given string S, find out the P (repetitive pattern) of S.| Report Duplicate | Flag | PURGE

Google Software Engineer - 0of 0 votes

AnswersFind if the characters of the sample string is in the same order in the text string.. Give a simple algo..

- sachin.and3 October 18, 2015 in United States

Eg.. TextString: abcNjhgAhGjhfhAljhRkhgRbhjbevfhO

Sample string :NAGARRO| Report Duplicate | Flag | PURGE

Nagarro Java Developer Algorithm Arrays Brain Storming Brain Teasers Coding Hash Table String Manipulation - 2of 2 votes

AnswersYou are given a String of number characters (S), like the following for example:

- SK January 15, 2015 in United States

"132493820173849029382910382"

Now, let's assume we tie letters to numbers in order such that:

A = "0"

B = "1"

C = "2"

...

M = "12"

N = "13"

...

Y = "24"

Z = "25"

Write an algorithm to determine how many strings of letters we can make with S, by converting from numbers to letters.| Report Duplicate | Flag | PURGE

Google - 1of 1 vote

AnswersWrite a program to accept a nonempty string of alphanumeric characters. Define a “run” as a

- PioneerWoman March 06, 2014 in United States

consecutive sequence of a single character. For example, “aaaa” is a run of length 4. The program will

print the longest run in the given string. If there is no single longest run, then you may print any of

those runs whose length is at least as long as all other runs in the string.

Example input: a

Example output: a

Example input: aab

Example output: aa

Example input: abbbbbcc

Example output: bbbbb

Example input: aabbccdd

Example output: aa| Report Duplicate | Flag | PURGE

Bloomberg LP Software Engineer / Developer - 5of 5 votes

AnswersGiven "n", generate all valid parenthesis strings of length "2n".

- anusha136 December 02, 2013 in United States

Example:

Given n=2

Output:

(())

()()| Report Duplicate | Flag | PURGE

Facebook Intern Algorithm - 5of 5 votes

AnswersGiven a set of numbers, find the longest subset with consecutive numbers be it any order.

- anonymous June 14, 2013 in India

Input:

S = { 5, 1, 9, 3, 8, 20, 4, 10, 2, 11, 3}

we have 2 consecutive sets

s1 = {1, 2, 3, 4, 5}

s2 = { 8, 9, 10, 11}

Ans.

s1 = {1, 2, 3, 4, 5}| Report Duplicate | Flag | PURGE

Google Applications Developer Algorithm - 2of 2 votes

AnswersWrite a method that multiplies two integers without using multiply operator

- S.Abakumoff February 25, 2013 in United States| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - 1of 1 vote

AnswersGiven a string we have to find first non-repeating character in the string....

- varunesh.88 December 07, 2012 in India

Example: str="aabbbccccddeffffgg";

Answer is : e| Report Duplicate | Flag | PURGE

Morgan Stanley Intern C - 2of 2 votes

AnswersGiven an array, find all maximal sub-arrays in which all pairs have their sum greater than k. DP would give us a O(n^2) algorithm. Can we do better.

- Vikas October 29, 2012 in United States

suppose k = 4

-4 9 10 4 -3 8 9 -2

Answer is:

-4 9 10

9 10 4

-3 8 9

8 9 -2| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Algorithm - 0of 0 votes

Answersn numbers (both +ve and -ve) are arranged in a circle. find the maximum sum of consecutive nos. Do this in O(n) time

- codez July 03, 2012 in United States

E.g.: {8,-8,9,-9,10,-11,12}

max = 22 (12 + 8 - 8 + 9 - 9 + 10)| Report Duplicate | Flag | PURGE

Microsoft - 0of 0 votes

AnswersGiven an Array With random 0s and non 0 numbers, shift all the 0s to the beginning and non 0s to the rear.

- soundararajanaravind March 06, 2012 in India

Eg: 1,9,8,4,0,0,2,7,0,6,0

Out put 0,0,0,0,1,9,8,4,2,7,6

i.e order of numbers not to change. Do it in place| Report Duplicate | Flag | PURGE

Microsoft Student student Arrays - 0of 0 votes

AnswersGiven (i) a non-empty binary search tree with double values (e.g. 3.5) in each node and (ii) a key value K

- mihirk February 15, 2012 in United States

Write a method to find the closest value to K.| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm Coding Data Structures Java Trees and Graphs - 1of 3 votes

AnswersGiven an inorder traversal only for a binary tree (not necessarily a

- Bugaboo December 27, 2011 in United States

BST), give a pseudo code to generate all possible binary trees for

this traversal sequence.

Firstly, how many binary trees can be generated given an in-order

traversal? I know that given 'n' nodes, number of BTs possible is

(2^n)-n. But if we are given a specific in-order sequence, can we cut

down on this number?| Report Duplicate | Flag | PURGE

Google

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

Open Chat in New Window