Recent Interview Questions
- 0of 2 votes
AnswersGiven an array, find the first element that appears an even number of times.
- techinterviewsintesys December 14, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Applications Developer - 2of 2 votes
AnswersA multiset or a bag is a collection of elements that can be repeated. Contrast with a set, where elements cannot be repeated.
- ersegun August 20, 2015 in Netherlands
Multisets can be intersected just like sets can be intersected.
Input :
A = [0,1,1,2,2,5]
B = [0,1,2,2,2,6]
Output :
A ∩ B = C = [0,1,2,2]
Input :
A = [0,1,1]
B = [0,1,2,3,4,5,6]
Output
A ∩ B = C = [0,1]
Write a function to find the intersection of two integer arrays in that way ?| Report Duplicate | Flag | PURGE
Booking.com Software Developer String Manipulation - 1of 3 votes
AnswersWe know a string is Palindrome if it is the same reading from both sides. Now we define the following string also Palindrome:
- amirtar May 05, 2015 in United States
A man, a plan, a canal, Panama!
Write a code that returns if an string is palindrome and it should return true for above input. (Without directly saying, I should conclude that I have to only consider alphanumerical characters in a string). In addition, we assume the string is very long and we can not keep a copy of this string or even a copy of preprocessed version of this string. Therefore the result should be returned with the first sweep of the string.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm String Manipulation - 1of 1 vote
AnswersPermutate a list of string
- HBY April 17, 2015 in United States
this question is supposed permutate the characters instead of who string,
as input example {"red", "fox", "super" }, the expected output is
rfs
rfu
rfp
rfe
rfr
ros
rou
rop
roe
ror
rxs
rxu
rxp
rxe
rxr
efs
efu
efp
efe
efr
eos
eou
eop
eoe
eor
exs
exu
exp
exe
exr
dfs
dfu
dfp
dfe
dfr
dos
dou
dop
doe
dor
dxs
dxu
dxp
dxe
dxr| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 3 votes
AnswersYou are given a 2D Array that contains only 0s and 1s in sorted order. i.e. First Os and then 1s.
- tihor January 24, 2015 in India
Array:
0 0 0 1
1 1 1 1
0 0 1 1
0 1 1 1
You have to figure out the row that contains maximum number of 1s.
e.g. in above case we have row 2 as the answer.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersFind the unique number that is present only once in array while all the others are present three times.
- Rahul Sharma November 03, 2014 in India
Example: 2,3,5,1,2,2,5,3,5,3
Answer : 1 as 2,3,5 are repeated three times
Complexity should be better than O(nlogn)| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Algorithm - 2of 2 votes
AnswersGenerate MAX_INT (Max signed int value) using bitwise operators. Should work in 32 and 64 bit processors
- bartcois January 28, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Bit Manipulation - 1of 1 vote
AnswersGiven an 8x8 chess board, you have a bishop that moves from the current to the target position. write a code to find the minimum path from the current to the target position.
- AVK June 15, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 3of 3 votes
AnswersThere are N floors and N persons each one is tagged with some random unique number between 1 to N(represents floor number).
- bharat May 31, 2013 in India
We have a lift which can accommodate one person at a time. Every person is in some random floor.
Initially lift is at floor 1 and all floors have single person. Problem here is.. we have to move the persons to their corresponding floor with minimum travelled distance of lift.
Restriction : Lift can have at most one person at a time.
One more thing we have to think of is .. At a time, we can keep more than one person in a floor.. means, we don't necessarily need to take the person out from the floor if we keep another person on the same floor.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 4of 4 votes
AnswersI Got this Crazy Question on PHONE INTERVIEW AT GOOGLE:
- hhh April 11, 2013 in United States
Design and implement a class to generate random numbers in an arbitrary probability distribution given by an array of integer weights, i.e. for int[] w return a number, n, from 0 to w.length - 1 with probability w[n] / sum(w). Using an existing random number generator with a uniform distribution is permitted.
Example distribution:
w = 1, 2, 3, 2, 1
Example probabilities:
w / sum = 1/9, 2/9, 1/3, 2/9, 1/9
Example results:
n = 0, 1, 2, 3, 4
Documentation:
Class java.util.Random
public int nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextInt is that one int value in the specified range is pseudorandomly generated and returned. All n possible int values are produced with (approximately) equal probability.
Parameters:
n - the bound on the random number to be returned. Must be positive.
Returns:
the next pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive) from this random number generator's sequence
Throws:
IllegalArgumentException - if n is not positive| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 3of 3 votes
AnswersImplement LookAndSay function. For example, first, let user input a number, say 1. Then, the function will generate the next 10 numbers which satisfy this condition:
- Kevin February 22, 2013 in United States
1, 11,21,1211,111221,312211...
explanation: first number 1, second number is one 1, so 11. Third number is two 1(previous number), so 21. next number one 2 one 1, so 1211 and so on...| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 1of 1 vote
AnswersThere are 2 sorted sets.Find the common elements of those sets
- anonymous February 22, 2013 in United States
e.g.
A={1,2,3,4,5,6}
B={5,6,7,8,9}
o/p C={5,6}
Complexity should ne 0(n+m) where n and m is the size of the first and second set respectively
Which data structure should be used to store the output| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm Data Structures - 0of 0 votes
AnswersGive a min and max of an integer array, write a function to randomly return a number inside of this range, but not in the list. Also write a class that contains this function.
- cqyanbo January 05, 2013 in United States for Google New York City| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Arrays - 0of 0 votes
AnswersWrite a program that takes an array of numbers, and then prints out all the possible pairs of numbers that sum up to the value N.
- Anil December 23, 2012 in United States for AWS
E.g., if the array contains the numbers {0, 1, 2, 2, 3, 4, 5} and the target value N is 4, then the output would be (0, 4), (1, 3), (2, 2).| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Java - 0of 0 votes
AnswersGiven two arrays, A and B, both containing integers, find values that appear in both arrays and output them.
I knew the fastest answer to this, which is basically adding array A to a hashmap and then checking if that map contains each element of B, which is an O(n) operation, but uses memory in O(n) as well. The interviewer then asked if I could figure a way of doing this with a complexity of O(n) without using any extra memory, basically just O(1) for memory.
Is this possible? I could not think of a simple quick solution for this on the fly, but I imagine it is possible.
Here is the code I wrote during the interview.import java.util.*; public class ArrayFun { public static void main(String[] args) { int[] a = {1,2,3,4}; int[] b = {2,5,6,7,3,2}; ArrayList<Integer> matches = ArrayFun.findMatches(a,b); for (int i = 0;i<matches.size();++i) { System.out.println(matches.get(i)); } } public static ArrayList<Integer> findMatches(int[] a, int[] b) { HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); ArrayList<Integer> matches = new ArrayList<Integer>(); for (int i = 0;i<a.length;++i) { map.put(a[i],0); } for (int i = 0;i<b.length;++i) { if (map.get(b[i]) != null && map.get(b[i]) == 0) { map.put(b[i],1); matches.add(b[i]); } } return matches; } }
Also, another quick question, is it typical for a phone interviewer to only ask you one question? I think it would be kind of difficult to ask more than one technical question, including coding, in such a short amount of time, i.e. < 1 hour
- M.Zimmerman6 November 08, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 0of 0 votes
AnswersRemove all two zeros in the given string.
- Naveen Reddy Mandadi August 25, 2012 in India
Example: a3409jd00dk000d
Output: a3409jddk000d
Note: If there are less/more than two zeros consecutive, it should not be replaced.| Report Duplicate | Flag | PURGE
Microsoft Applications Developer Algorithm - 0of 0 votes
AnswersHow do you partition an array into 2 parts such that the two parts have equal average? Each partition may contain elements that are non-contiguous in the array..
- GillY January 17, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Algorithm - 0of 0 votes
AnswersHow to rotate the array with o(n) or o(nlogn)/
- JobHunter November 11, 2011 in United States
eg) A[]={A,B,C,D,E} rotate Index - 2
It should be {C,D,E,A,B}| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays - -2of 2 votes
AnswersRank a list without sorting it.
- newbie September 07, 2011 in India
List : [6, 3, 9]
Rank : [1, 0, 2]
algo & then code it efficiently| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersQ1) Write a program to calculate height of a binary tree non - recursively ?
- Decipher August 13, 2011
Q2) Asked which data structure should be used to store browser history.
Q3) Find the anagrams with a huge list of words .
Q4) Mirror a tree iteratively.
Q5) Compute a+bx2+cx3+dx4+... efficiently (a,b,c...given)
Q6) Find one missing alphabet in an array of 26 alphabets(one alphabet repeated twice).| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a BST and integer value K.
- anonymous June 17, 2011
Find two nodes x and y such that x->data + y->data = K
Time O(n), space O(1)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer - 0of 0 votes
AnswersPrint a linked list recursively in a reverse manner without changing the actual list
- fuckubloomberg July 26, 2009| Report Duplicate | Flag | PURGE
Bloomberg LP Amazon Financial Software Developer Software Engineer / Developer Linked Lists - 0of 0 votes
AnswersAn array A[1...n] contains all the integers from 0 to n except one. In this problem, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is "fetch the jth bit of A[i]", which takes constant time. Find the missing integer in O(n) time.
- AK47 November 08, 2007| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Math & Computation Data Structures Coding Algorithm - 1of 0 votes
Answersi have number of 10 digits lets say
- Subhash April 02, 2007
ABCDEFGHIJ
A represents the number of 0's the above number has,B contains the number of 1's the above number has and so on...
Can you find out that number......| Report Duplicate | Flag | PURGE
Oracle Software Engineer / Developer Brain Teasers - 1of 1 vote
AnswersGiven a length n, count the number of strings of length n that can be made using ‘a’, ‘b’ and ‘c’ with at-most one ‘b’ and two ‘c’s allowed.
- Nits September 07, 2019 in United States| Report Duplicate | Flag | PURGE
Facebook Software Development Manager Algorithm - 1of 1 vote
AnswersPrint series 010203040506. Using multi-threading 1st thread will print only 0 2nd thread will print only even numbers and 3rd thread print only odd numbers.
- neer.1304 September 04, 2017 in United States| Report Duplicate | Flag | PURGE
Goldman Sachs SDE-2 Threads - 0of 0 votes
Answerslist1 -->aaa,bbb,ddd,xyxz,...
- codemarathon February 09, 2017 in United States
list2-->bbb,ccc,ccc,hkp,..
list3> ddd,eee,,ffff,lmn,..
Inside a list the words are sorted
I want to remove words which are repeated across the list and print in sorted order
If the words are repeated in same list its valid.
In the above case
it should print aaa-->ccc-->ccc-->eee--->fff-->glk-->hkp-->lmn-->xyxz| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 7of 7 votes
AnswersYou are given a graph with no cycles, each node representing different cities and there are stadiums for baseball games in all cities.
Each node contains a value representing the population of the city, and a list of neighbors. (feel free to extend data structure)
Every time there is a baseball game at a city, everyone from all the different cities will go to the city with the baseball game.
Return the maximum traffic between a city and its neighbours when there is a game at that city, for all cities. (Does not have to be sorted)
The total run-time after returning everything should be O(n).
Examples:
- djway August 10, 2016 in United StatesInput: 1 2 \ / 5 / \ 4 3 Output: 1 14 2 13 3 12 4 11 5 4 Input: 38 / 8 / 7 / 1 2 \ / \ 5 15 / \ 4 3 Output: 1 82 2 53 3 80 4 79 5 70 7 46 15 68 8 38 38 45
| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Trees and Graphs - 3of 3 votes
Answers# take an array and print non over lapping in order pairs. example:
- thegeek21 June 05, 2016 in United States# [1,2,3,4] => input # output below is in order combination # (1234) # (1)(234) # (1)(23)(4) # (1)(2)(34) # (12)(34) # (12)(3)(4) # (123)(4) # (1)(2)(3)(4)
| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm