Recent Interview Questions
- 22of 38 votes
AnswersGive you an array which has n integers,it has both positive and negative integers.Now you need sort this array in a special way.After that,the negative integers should in the front,and the positive integers should in the back.Also the relative position should not be changed.
- lxfuhuo August 23, 2013 in CHINA
eg. -1 1 3 -2 2 ans: -1 -2 1 3 2.
o(n)time complexity and o(1) space complexity is perfect.| Report Duplicate | Flag | PURGE
Google Intern Algorithm - -1of 1 vote
Answerstest cases for atm
- coder August 03, 2013 in United States| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersHow would you test a vending machine?
- Anonymous October 08, 2009| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Testing - 11of 15 votes
AnswersGiven an int array which might contain duplicates, find the largest subset of it which form a sequence.
- learner October 06, 2011 in -
Eg. {1,6,10,4,7,9,5}
then ans is 4,5,6,7
Sorting is an obvious solution. Can this be done in O(n) time| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Software Engineer / Developer Arrays Algorithm - -2of 2 votes
Answers100% Get The Lucky Winning Numbers By Powerful And Trusted Lottery Spell Caster +27789456728 In The World and Usa,Uk,Canada.
- profmamaHanisha February 21, 2018 in United States
Winning isn't just luck it is about your positive energy and how you can utilize positive energy from the universe to change your bad luck to good luck and earning heaps of money.
There are couple of lucky individuals who have won lotteries, yet again they are likewise conventional individuals like us, the main thing is that you have the positive energy that profits stars exceptionally strong and powerful and when this happens, you ingest energy from the universe which again makes your sub cognizant personality powerful so your mind reveals to you which lottery you need to take and furthermore from where you need to take and after that when the outcomes are out their life changes.
Life isn't simple and to survive you have to earn money, and furthermore having luck on your side can help you in carrying on with a happy and successful life, and spell cast of lottery spell isn't bad, you are just taking help of the universe and its powers to achieve your objectives, as the spell will help you expanding your positive energy that will ingest powers of the universe to help you.
http://www.profmamahanisha.com/ email.www.info@profmamahanisha.com call +27789456728/ WHATSSAP| Report Duplicate | Flag | PURGE
Alliance Global Servies Consultant - 5of 5 votes
AnswersGiven a N*N Matrix.
- 646 November 23, 2010
All rows are sorted, and all columns are sorted.
Find the Kth Largest element of the matrix.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 4of 4 votes
AnswersIf [a1,a2,a3...,an,b1,b2...bn] is given input change this to [a1,b1,a2,b2.....an,bn] , solution should be in-place
- Anonymous February 05, 2011| Report Duplicate | Flag | PURGE
Amazon Microsoft Developer Program Engineer Software Engineer / Developer Algorithm Arrays - 2of 2 votes
AnswersRound 1: Q2:
- Abee July 20, 2011
Puzzle
Given 25 horses, find the best 3 horses with minimum number of races. Each race can have only 5 horses. You don't have a timer.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Brain Teasers Highbridge Capital Deshaw Inc - 18of 18 votes
AnswersIf a=1, b=2, c=3,....z=26. Given a string, find all possible codes that string can generate. Give a count as well as print the strings.
- diffuser78 June 07, 2013 in United States
For example:
Input: "1123". You need to general all valid alphabet codes from this string.
Output List
aabc //a = 1, a = 1, b = 2, c = 3
kbc // since k is 11, b = 2, c= 3
alc // a = 1, l = 12, c = 3
aaw // a= 1, a =1, w= 23
kw // k = 11, w = 23| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm Coding - 4of 8 votes
AnswersDesign an algorithm that, given a list of n elements in an array, finds all the elements that appear more than n/3 times in the list. The algorithm should run in linear time ( n >=0 )
- Aashish June 27, 2012 in India
You are expected to use comparisons and achieve linear time. No hashing/excessive space/ and don't use standard linear time deterministic selection algo| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersPath to deepest 1 in a binary tree.
- shilpa February 02, 2011
We have a binary tree (not a BST) made up of only 0s and 1s. we need to find the deepest 1 with a path from root made up only of 1's.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm - 2of 2 votes
Answersfind the longest palindrome in a string?
- handiaya November 09, 2009| Report Duplicate | Flag | PURGE
Microsoft Amazon Software Engineer / Developer Algorithm Arrays C++ Coding String Manipulation C - 19of 19 votes
AnswersGiven two strings a and b, find whether any anagram of string a is a sub-string of string b. For eg:
- Masterchief117 March 23, 2014 in United States
if a = xyz and b = afdgzyxksldfm then the program should return true.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer String Manipulation - 0of 0 votes
AnswersDesign an ATM machine system..
- TechPrep December 20, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon System Design - 33of 39 votes
AnswersGiven an array of integers. Find two disjoint contiguous sub-arrays such that the absolute difference between the sum of two sub-array is maximum.
- LAP June 10, 2013 in United States
* The sub-arrays should not overlap.
eg- [2 -1 -2 1 -4 2 8] ans - (-1 -2 1 -4) (2 8), diff = 16
I gave him o(n^2) algorithm but he was not satisfied.| Report Duplicate | Flag | PURGE
Google Algorithm - 2of 2 votes
Answersgive me the code for :
Given a string say "I am a human being" the output should reverse all letters of each word but not the whole string as such.
Eg: O/p should be "I ma a namuh gnieb"
I somewhat wrote the code, but i was asked what if there are extra spaces etc.
(i am able to write the code sitting at my desktop at one short but there front of interviewer i am struggling. Need to build up my confidence)
let me know the best and optimised way of writing this code.
Also i suggest people to aviod using inbuilt functions as much as possible
My Answer is as below in perl
- i_learn April 11, 2014 in India#i want the reverse of the letters of all words in a string #eg Input is "I am a human being" then o/p shud be "I ma a namuh gnieb" $str="I am a human being"; @arr=split(' ',$str); print @arr; for($i=@arr-1;$i>=0;$i--) { $_=@arr[$i]; ####intead of above for loop if we use foreach(@arr) then it will reverse the whole string @word=split('',$_); { foreach $n (@word) { unshift(@final,$n); } } } print "\n @final \n";
| Report Duplicate | Flag | PURGE
Amazon Testing / Quality Assurance Algorithm Android Application / UI Design Arrays Automata Coding Data Structures Dynamic Programming Perl - 77of 79 votes
AnswersYou have k lists of sorted integers. Find the smallest range that includes at least one number from each of the k lists.
- ericaturner0 April 01, 2013 in United States
For example,
List 1: [4, 10, 15, 24, 26]
List 2: [0, 9, 12, 20]
List 3: [5, 18, 22, 30]
The smallest range here would be [20, 24] as it contains 24 from list 1, 20 from list 2, and 22 from list 3.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 3of 3 votes
Answersone unsorted array is given.Find out the index i and j ,j> i for which a[j] - a[i] is maximum.perform in linear time complexity
- rahul baid February 17, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Data Structures Arrays - 4of 4 votes
AnswersYou are given a string S and a set of n substrings. You are supposed to remove every instance of those n substrings from S so that S is of the minimum length and output this minimum length.
- pnkapadia6 June 08, 2014 in India
Eg:
S- ccdaabcdbb
n=2 - substrings-- ab, cd
Output: 2
Explanation:
ccdaabcdbb -> ccdacdbb -> cabb -> cb (length=2)
Can someone help me with the algo?| Report Duplicate | Flag | PURGE
Hackerrank Software Engineer Intern String Manipulation - 33of 35 votes
AnswersA k-palindrome is a string which transforms into a palindrome on removing at most k characters.
- sc.shobhit August 28, 2013 in India
Given a string S, and an interger K, print "YES" if S is a k-palindrome; otherwise print "NO".
Constraints:
S has at most 20,000 characters.
0<=k<=30
Sample Test Case#1:
Input - abxa 1
Output - YES
Sample Test Case#2:
Input - abdxa 1
Output - No| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm - 1of 1 vote
AnswersPush all the zero's of a given array to the end of the array. In place only. Ex 1,2,0,4,0,0,8 becomes 1,2,4,8,0,0,0
- CheckThisResume.com March 09, 2012 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm Arrays C Coding - 8of 8 votes
Answers1. qaz is a value for a number where this number is less than the other next values which have indexes larger than the index of this number.
- Pointer January 27, 2015 in United States for Autocomplete
for example: 33 , 25 , 26 , 58 , 41 , 59 -> qaz of (33) = 3 where 33 less than 3 numbers (58 , 41 , 59), qaz of (25) = 4 and not 5 because the index of 33 is less than the index of 25, qaz of (26) = 3 , qaz of (58) = 1 , qaz of (41) = 1 , qaz of (59) = 0.
the question is to find the max qaz.
it can be solved simply using 2 loops which takes time of O(n^2).
that's ok but how can we solve this problem in O(nlogn).
I have an approach and know the algorithm I got during the interview but it take a 40 of me to find it and write the code, but it was hard to think about it during the interview in that way.
I want to know if somebody can think and write the code in less than 20 minutes !!!| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 3of 3 votes
AnswersATM has x currency notes of 100 rupee,y currency notes of 500 rupee,and z currency notes of 1000 rupee notes.
- rajat sadh January 10, 2016 in India
Customer wants to withdraw n amount at any given time. as per bank rules,Customer can not withdraw more than INR.40000/-per transaction.
If ATM is running out of cash it should throw a message that insufficient Balance, Kindly enter multiple of m value of currency note.where m>=4000 and m<=total number of cash available in ATM.
An intelligent banker has found in customer survey that customer prefers to receive more than 5 currency notes 100 rupee,more than 2 currency noes of 500 rupee and rest of the currency notes is of 1000 rupee where ever possible.
If amount is less than 500,customer will receive 100 rupee currency notes. Bankers goal is to tender the minimum number of currency notes to save customer waiting time and increase customer satisfaction by following customer survey.Banker has hired you to program ATM dissaptch function.
FOR Example: Lets ATM has 200 currency notes of 100 rupees,90 currency notes of 500 rupee and 50 currency notes of 1000 rupee.Customer has placed a withdrawal request of Rs 22,200.00. Dispatch function has given him 7 currency notes of 100,3 currency notes of 500 and 20 currency notes of 1000 rupee| Report Duplicate | Flag | PURGE
Adobe SDE1 Algorithm - 1of 1 vote
AnswersYou are given an array ' containing 0s and 1s. Find O(n) time and O(1) space
- Anonymous August 25, 2010
algorithm to find the maximum sub sequence which has equal number of 1s and
0s.
Examples
1) 10101010
The longest sub sequence that satisfies the problem is the input itself
2)1101000
The longest sub sequence that satisfies the problem is 110100| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 4of 6 votes
Answersgiven an int array with no duplicate numbers, write a function to return number of ways to calculate a target number.
- cooldog March 15, 2013 in United States
example: given {2,4,6,8} Target = 12
2 + 4 + 6 = 12,
4 + 8 = 12,
6 + 8 - 2 = 12,
2 - 4 + 6 + 8 = 12,
return 4| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Software Engineer in Test - 4of 4 votes
AnswersWe have an array of objects A and an array of indexes B. Reorder objects in array A with given indexes in array B. Do not change array A's length.
example:
- u-11i24223 October 26, 2015 in United Statesvar A = [C, D, E, F, G]; var B = [3, 0, 4, 1, 2]; sort(A, B); // A is now [D, F, G, C, E];
| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer Front End Web Development - 1of 1 vote
AnswersImplement the plusplus operator when we are getting the input as integer array = { 9,9,9,9 }.output will be {1,0,0,0,0}
- JobHunter July 11, 2012 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Arrays C Coding Data Structures - 2of 0 votes
AnswersSimulate a seven-sided die using only five-sided
- vodangkhoa March 23, 2008| Report Duplicate | Flag | PURGE
Amazon Microsoft Software Engineer / Developer Algorithm - 5of 5 votes
AnswersThree strings say A,B,C are given to you. Check weather 3rd string is interleaved from string A and B.
- learn August 27, 2012 in United States
Ex: A="abcd" B="xyz" C="axybczd". answer is yes. o(n)| Report Duplicate | Flag | PURGE
Google - 12of 12 votes
AnswersGiven a string which only contains lowercase. You need delete the repeated letters only leave one, and try to make the lexicographical order of new string is smallest.
- lxfuhuo September 09, 2015 in -
i.e:
bcabc
You need delete 1 'b' and 1 'c', so you delete the first 'b' and first 'c', the new string will be abc which is smallest.
ps: If you try to use greedy algorithm to solve this problem, you must sure that you could pass this case:
cbacdcbc. answer is acdb not adcb
I can't solve this problem well and the interviewer said that you can scan the string twice. First scan is do some preprocess, and the second is to get the answer, but I really can't come up this idea.| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm