Recent Interview Questions
- 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 - 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 Statespublic 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 - 2of 2 votes
AnswersGiven a list of arrays of time intervals, write a function that calculates the total amount of time covered by the intervals.
- aonecoding4 January 19, 2019 in United States
For example:
input = [(1,4), (2,3)]
return 3
input = [(4,6), (1,2)]
return 3
input = {{1,4}, {6,8}, {2,4}, {7,9}, {10, 15}}
return 11| Report Duplicate | Flag | PURGE
Facebook 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