Amazon Interview Report
- 0of 0 votes
Answers3.Find the first unique character in a Stream. Please note that you are being provided a stream as a source for these characters.
- kumar.prince6 January 13, 2013 in India
The stream is guaranteed to eventually terminate (i.e. return false from a call to the hasNext() method), though it could be very long. You will access this stream through the provided interface methods.
A call to hasNext() will return whether the stream contains any more characters to process.
A call to getNext() will return the next character to be processed in the stream.
It is not possible to restart the stream.
If there is no unique character, then return the character '#'. # won't be any character in the character stream.
You just have to complete the function getUniqueCharacter() using the functions hasNext() and getNext() which are already defined.
Example:
Input:
aAbBABac
Output:
b
Input:
aBBa
Output:
#| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
Answers1.You are given a function calcDifference which takes in the root pointer of a
- kumar.prince6 January 13, 2013 in India
binary tree as it's input. Complete the function to return the sum of values of nodes at
odd height - sum of values of node at even height. Consider the root node is at height 1
/* Write your own custom functions here */
int calcDiff(node * root){
/*
struct node {
struct node *left,*right;
int val;
node(int x){
val = x;
}
};
typedef struct node node;
The structure is already declared, you can just start initializing nodes
*/
}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 0of 0 votes
Answers2.Given an integer linked list of which both first half and second half are sorted independently. Write a function to merge the two parts to create one single sorted linked list in place [do not use any extra space].
- kumar.prince6 January 13, 2013 in India
Sample test case:
Input: List 1:1->2->3->4->5->1->2; Output: 1->1->2->2->3->4->5
Input 2: 1->5->7->9->11->2->4->6; Output 2: 1->2->4->5->6->7->9->11
C/C++/Java/C#
struct node
{
int val;
node *next;
}
node* sortList(node* list1) {
}
Java
class Node
{
int val;
Node next;
}
Node sortList(Node list1) {
}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer