Recent Interview Questions
- 0of 0 votes
AnswersGiven a string representing relative path write a function which normalizes this path (i.e. replaces "..").
- Eugene July 16, 2015 in United States
Example:
input: \a\b\..\foo.txt
output: \a\foo.txt| Report Duplicate | Flag | PURGE
Google Software Engineer - 2of 2 votes
AnswersTech Screening
- sonesh July 02, 2015 in United States
Question 1 : You will be given a stream of integers, and a integer k for window size, you will only receive the streams integers one by one. whenever you receive an integer, you have to return the maximum number among last k integers inclusive of current entry.
Interviewer was expecting O(N) solution for N asks.
Edits: Interviewer was expecting O(N) Time + O(1) avg case space complexity solution for N asks.
and integers are not given in a array, every time only one integer will be passed as input to your method.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Arrays Data Structures - 2of 2 votes
AnswersAn array consist of elements whose difference is positive or negative 1. I have to find the given elements without using linear search.
- thilaksmile June 15, 2015 in India
Say
Int arr[]={1,2,3,4,3,4,5,6,7
To find : 6
.
Please provide some one code/algorithm for this problem.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer - 1of 1 vote
AnswersTell the following 3 letter in the sequence
- qe.expert March 18, 2015 in India
A E F H I K _ _ _| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Brain Teasers - 0of 0 votes
AnswersInput any string, count the maximum depth of parenthesis nesting, i.e. "abc(123(xyz))m(((n)))o" -> 3.
- jobPrep February 23, 2015 in United States
if input is null or contains a mismatch "a)b(c" or "a(b"
Also some other samples:
(((()))) -> 4
()()()() -> 1| Report Duplicate | Flag | PURGE
Walmart Labs Coding - 4of 4 votes
AnswersGiven the relative positions (S, W, N, E, SW, NW, SE, NE) of some pairs of points on a 2D plane, determine whether it is possible. No two points have the same coordinates.
- united November 02, 2014 in United States
e.g., if the input is "p1 SE p2, p2 SE p3, p3 SE p1", output "impossible".| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersJava: You're given a very large array of char's. Write a method to remove duplicates in the array, in place. Optimize for space complexity, not time complexity.
- davelee71047 October 24, 2014 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Intern Arrays - 5of 5 votes
AnswersGiven a Sorted integer array which is rotated N number of times. You have no idea what that N is. An element in the array can occur more for any number of time. Write a method to search the position of a given element. If there are more than one of the same element, return the position of the first element.
- jeevanus September 04, 2014 in India for Microsoft CRM| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm Data Structures Sorting - 1of 1 vote
AnswersYou have 5 data sources. There is a program which calls these data sources and returns a count value.
You need to speedup this program. How do you do that?
This is a sample code
- dmrrb1980 July 01, 2014 in United Statesint count = getCount(ds1); if(count < 100 ) count = count + getCount(ds2); if(count < 100) count = count + getCount(ds3); if(count < 100) count = count + getCount(ds4); if(count < 100) count = count + getCount(ds5);
| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Threads - 4of 4 votes
AnswersImplement a method called printNonComments() which prints out a extract of text with comments removed.
- Ash June 30, 2014 in UK
For example, the input:
hello /* this is a
multi line comment */ all
Should produce:
hello
all
You have access to a method called getNextLine() which returns the next line in the input string.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a number N. find is it perfect square or not. cannot use any library functions.
- Vin April 05, 2014 in India| Report Duplicate | Flag | PURGE
Ebay Software Engineer / Developer - 2of 4 votes
AnswersGiven an Array, replace each element in the Array with its Next Element(To its RHS) which is Larger than it. If no such element exists, then no need to replace.
- R@M3$H.N March 03, 2014 in United States
Ex:
i/p: {2,12,8,6,5,1,2,10,3,2}
o/p:{12,12,10,10,10,2,10,10,3,2}| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 9of 9 votes
AnswersMicrosoft Excel numbers cells as 1...26 and after that AA, AB.... AAA, AAB...ZZZ and so on.
- Interviewee February 27, 2014 in United States
Given a number, convert it to that format and vice versa.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 1of 1 vote
AnswersIn Amazon's interview, Round 2 they asked question:
Write a program to print inorder traversal of two trees.
Both values must be printed alternatively.
e.g. if inorder traversal of tree 1 is 10, 15, 20 and tree 2 is 100, 150, 200 then it should print
10, 100, 15, 150, 20, 200.
I tried printing it recursively by calling 2 functions recursively (f1 calls f2, then f2 calls f1 and so on).
I don't know where my approach is going wrong? I know there are other ways to do it as well but in this approach what is the mistake?
- tihor February 22, 2014 in Indiapublic class HelloWorld{ //this is the Node used in the tree static class Node{ private int data; private Node left; private Node right; public Node(int data){ this.data = data; left = null; right = null; } public void setLeft(Node left){ this.left = left; } public void setRight(Node right){ this.right = right; } public Node getLeft(){ return this.left; } public Node getRight(){ return this.right; } public int getData(){ return this.data; } public boolean equals(Node n){ if(this.data ==(int) n.getData()) return true; else return false; } } public static void main(String[] args){ HelloWorld bts = new HelloWorld(); bts.run(); } //execute the test case public void run(){ Node root = new Node(10); insert(root,new Node(20)); insert(root,new Node(50)); insert(root,new Node(40)); insert(root,new Node(15)); Node node2 = new Node(100); insert(node2,new Node(200)); insert(node2,new Node(500)); insert(node2,new Node(400)); insert(node2,new Node(150)); //inOrderTraverse(node2); inOrderTraverse1(root, node2); } // insert a node to the binary search tree public void insert(Node root, Node n){ if(root == null|| n == null) return; if(root.getData() > n.getData()){ if(root.getLeft() == null){ root.setLeft(n); }else{ insert(root.getLeft(),n); } }else if(root.getData() < n.getData()){ if(root.getRight() == null){ root.setRight(n); }else{ insert(root.getRight(),n); } } } public void inOrderTraverse(Node node){ if(node != null){ if(node.getLeft() != null) inOrderTraverse(node.getLeft()); System.out.print(" "+node.getData()); if(node.getRight() != null) inOrderTraverse(node.getRight()); } } //in-order Traversal public void inOrderTraverse1(Node node1, Node node2){ if(node2 != null){ inOrderTraverse2(node1, node2.getLeft()); System.out.println(" "+node2.getData()); inOrderTraverse2(node1, node2.getRight()); } } public void inOrderTraverse2(Node node1, Node node2){ if(node1 != null ){ inOrderTraverse1(node1.getLeft(), node2); System.out.println(" "+node1.getData()); inOrderTraverse1(node1.getRight(), node2); } }
| Report Duplicate | Flag | PURGE
Amazon Member Technical Staff Coding - 0of 0 votes
AnswersYou are given a binary array with N elements: d[0], d[1], ... d[N - 1].
- kesar January 02, 2014 in United States
You can perform AT MOST one move on the array: choose any two integers [L, R], and flip all the elements between (and including) the L-th and R-th bits. L and R represent the left-most and right-most index of the bits marking the boundaries of the segment which you have decided to flip.
What is the maximum number of '1'-bits (indicated by S) which you can obtain in the final bit-string?
'Flipping' a bit means, that a 0 is transformed to a 1 and a 1 is transformed to a 0 (0->1,1->0).
Input Format
An integer N
Next line contains the N bits, separated by spaces: d[0] d[1] ... d[N - 1]
Output:
S
Constraints:
1 <= N <= 100000
d[i] can only be 0 or 1f
0 <= L <= R < n
Sample Input:
8
1 0 0 1 0 0 1 0
Sample Output:
6
Explanation:
We can get a maximum of 6 ones in the given binary array by performing either of the following operations:
Flip [1, 5] ==> 1 1 1 0 1 1 1 0| Report Duplicate | Flag | PURGE
VMWare Inc Problem Solving - 1of 1 vote
AnswersGiven a list of ranges as input ((1,2),(3,4),(3,6),(8,10)),the output would be those ranges that don't overlap.For example, the output could be merging the ranges 1) (1,2),(3,4)
- aifra2000 December 02, 2013 in United States
2) (1,2) (3,6) etc
The output cannot contain (3,4),(3,6) as 3 is common to both| Report Duplicate | Flag | PURGE
Amazon Java Developer Java - 1of 1 vote
AnswersPrint words of given string in reverse:
- Shyam November 23, 2013 in India for Kindle
"This is test" -> "test is This"| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer - 5of 5 votes
AnswersGiven two sorted arrays, we can get a set of sums(add one element from the first array and one from the second). Find the Nth element in the set of sums. Suppose that array A is {1,3,4,8,10}, array B is {20, 22, 30, 40}. then the sum set will be{21(1+20),23(1+22 or 3+20), 25(3+22), 24(4+22)...} the 3rd element in the sum set is 25.
- ophis.W October 28, 2013 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Intern Algorithm - 4of 6 votes
AnswersYou have two integer arrays. Treat these arrays as if they were big numbers, with one digit in each slot. Perform addition on these two arrays and store the results in a new array.
- Aasen October 24, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Algorithm - 1of 3 votes
AnswersInput - List<String> ["star", "rats", "ice", "cie", "arts"]
print all anagrams in buckets:
["star", "rats", "arts"]
["ice", "cie"]
The signature of unimplemented method is given:public void anagramBuckets(List<String> input);
I was given this question during phone interview.
- sunnyhust2005 October 12, 2013 in United States for Facebook Android| Report Duplicate | Flag | PURGE
Facebook Applications Developer Algorithm - 5of 5 votes
AnswersInitially there is a number n written on board. Two players start playing a game turn by turn. Each player has to replace the number n written on the board by n-2^k (for some k >= 0 such that 2^k < n)?
- ACP Pradyuman October 03, 2013 in United States
Also the number n-2^k has to be as beautiful as n (The beauty of a number depends on the number of one's in its binary representation). The player loses the game when he can't select any such k.
Given the initial number n, determine which player will win the game if both players play optimally. n > 0 and n <= 10^9.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Bit Manipulation - -2of 2 votes
AnswersLongest increasing subsequence:
- pirate July 28, 2013 in United States
Given n numbers A1..An determine subsequence of maximum length values in the subsequence form a strictly increasing sequence.
ex: input 5,2,6,3,4,1,9,9,8,9,5
output: 2,3,4,8,9| Report Duplicate | Flag | PURGE
Yahoo Google Software Engineer / Developer Algorithm - 10of 10 votes
AnswersA tree, (NOT NECESSARILY BINARY), has nodes numbered 0 to N-1. An array has indices ranging from 0 to N-1. The indices denote the node ids and values denote the ids of parents. A value of -1 at some index k denotes that node with id k is the root. For ex:
3 3 3 -1 2 0 1 2 3 4
In the above, nodes with ids 0, 1 & 2 have 3 as parent. 3 is the root as its parent = -1 and 2 is the parent of node id 4.
- Murali Mohan July 22, 2013 in India for Bangalore
Given such an array, find the height of the tree.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 1of 3 votes
AnswersCode to find the Longest Increasing Subsequence of an array. Not the length but output the numbers.
- Nascent July 02, 2013 in India| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersGiven a number of N-digits A, I want to find the next least N-digit number B having the same sum of digits as A, if such a number exists. The original number A can start with a 0. For ex: A-> 111 then B-> 120, A->09999 B-> 18999, A->999 then B-> doesn't exist.
- srk.iitg June 19, 2013 in United States| Report Duplicate | Flag | PURGE
Problem Solving - 1of 1 vote
AnswersSort a singly-linked list of unknown size using constant space.
- trunks7j March 25, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 2 votes
Answersgiven a string in form of an array find an expanded string
- krish March 04, 2013 in India
e.g. A2B3C4 => AABBBCCCC
also, size of given array is exactly same as expanded string. so return the same array with expanded string.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 1of 1 vote
AnswersWrite a function, that given a list of integers and an integer s, prints any 2 numbers in the list that sum to s.
- overshine February 07, 2013 in United States
1, 2, 3, 4, 5 sum = 6 could print:
1 + 5 = 6
2 + 4 = 6
4 + 2 = 6
5 + 1 = 6| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm