Amazon Interview Questions
- 0of 0 votes
AnswersThere is a sorted array of infinite numbers (can contain duplicates). Given a number. Find the last occurring instance of that number in the array.
- Rahul November 21, 2012 in India for Kindle
Ex., i/p: 12344445566667789...
search number: 6
o/p: 12 (index)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersWrite an algorithm to print out how many extra duplicates there are in a binary search tree.
- sjs3 November 01, 2012 in United States for amazon local
input 1:
2
/ \
1 2
output 1:
2 1
input 2:
3
/ \
2 3
/ \ \
1 2 4
/ \
3 4
\
5
\
5
output 2:
2 1
3 2
4 1
5 1
Given:
Node {
int value;
Node left;
Node right;
}| Report Duplicate | Flag | PURGE
Amazon Trees and Graphs - 1of 1 vote
AnswersGiven a big unsorted list of 64-bit integers, find an element not in list
- novice September 15, 2011 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 0of 0 votes
Answers3. Given a number of nodes N of a binary tree , how many structurally different full binary trees are possible.
A binary tree is said to be full binary tree , if for every node in the tree there exists exactly zero or 2 children.
Example: When N = 5 , No. of possible trees = 2
- arun February 19, 2011o o / \ / \ o o o o / \ / \ o o o o
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersYou are given an array of length 99 that contains all the numbers between 1 and 100, except for one number that has been removed. Find the missing element.
- kunal chopra November 03, 2005| Report Duplicate | Flag | PURGE
Amazon Testing / Quality Assurance Arrays - 2of 2 votes
AnswersVerify if S2 = {5,8,2} is a subset of S1 = {1,5,4,6,8,2} and S3 = {5,8,2,7} is not a subset of S1.
- hadeebataj May 10, 2019 in India| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer String Manipulation - 0of 0 votes
AnswersFace to Face
- siva.sai.2020 November 29, 2015 in United States
Q4) two arrays given to you. First array contains number s. Second array contains key values.
We need to find smallest window in first array which covers all second array elements.
e.g:
Input= {6,7,1,3,2,4,5,2,3,1,2,5}
Keys = {2,5,1}
answer: from 9th index to 11th index is the smallest window.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersGiven 2D Array of only 0s and 1s, Find the row which gives max decimal value.
- Rajarathinam Antony November 22, 2015 in India
Input: int array[3][3] = {{0,1,0,}{1,1,0},{1,0,1}};
Output : 2(second row)...decimal value is 6| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 2 votes
AnswersGiven two strings, return true if they are one edit away from each other, else return false. An edit is insert/replace/delete a character.
- codewarrior September 07, 2015 in United States
Ex. {"abc","ab"}->true, {"abc","adc"}->true, {"abc","cab"}->false| Report Duplicate | Flag | PURGE
Amazon SDE1 - 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 - 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 - 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 - 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 - 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 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 - 0of 0 votes
AnswersGiven an array of 32bit unsigned integers in which every number appears exactly twice except three of them, find those three numbers in O(n) time using O(1) extra space. The input array is read-only. What if there are k exceptions instead of 3?
- Aashish August 12, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersSingly LL with value as character. Please find out the word formed by character LL is palindrome or not.
- Sanjay Kumar July 16, 2012 in India
Time Complexity <n^2
Space Complexity O(1)| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersInteger has been represented in linked list. Eg. 7541 has been represented as 7->5->4->1 with 4 nodes each having a digit. Given 2 such linked lists, you need to compute the sum of them.
- raghu.slp May 19, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
Answerswhat s next in this series
- saravan06psgtech August 08, 2009
sss,scc,c,sc,?????.| Report Duplicate | Flag | PURGE
Amazon Analyst Brain Teasers - 0of 0 votes
AnswersYou have eight balls: seven are the same weight, and one is heavier than the rest. Given a scale that only tells you which side is heavier, how do you find the heavy ball?
- SJ December 14, 2005| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Brain Teasers - 0of 0 votes
Answers1. Write a function that removes the duplicate of a collection of numbers and returns the number of elements remaining in the collection after the duplicates have been removed. You must ensure that duplicates are actually removed from the list.
- laurentr September 18, 2015 in United States
Example #1
Input
{1, 1, 5, 3, 8, 3, 7, 32, 32}
Output
6
Example #2
Input
{21, 10, 24, 2, 21}
Output
4
int removeDuplicates(List numbers) {
// your code goes here
}| Report Duplicate | Flag | PURGE
Amazon Software Developer - 2of 2 votes
AnswersGiven an array of strings with only lowercase letters , create a function that returns an array of those same strings, but each string has its letters rearranged such that it becomes a palindrome (if possible, if not, return -1)
- makingworldcode September 13, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer Java - 0of 2 votes
AnswersGiven an array of random integers and a sum value, find two numbers from the array that sum up to the given sum.
- shoryagupta1493 March 12, 2015 in United States for Amazon Fresh
eg. array = {2,5,3,7,9,8}; sum = 11
output -> 2,9
Implement in O(n) time complexity. Find all distinct pairs. (2,9) and (9,2) are not distinct.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm