Forum Posts
0 Answers Implement a rate-limiter-like iterator and how to improve the space complexity
Given a <Word, TimeStamp> pair data type iterator as input. Implement an iterator based on it which can ignore the item if the same word has occurred in the past 10 seconds.
- sun2gz July 05, 2018
My implementation is to use a HashMap to memorize the word and its latest timestamp + 10s. For each new item, it will be checked against the HashMap to see if it has duplicated word occurred in the past 10s.
The interviewer asked me how to improve the space complexity if the string value varieties are infinite. He mentioned some boundary stuff.
Could anyone share some thoughts?| Flag | PURGE 0 Answers Linked List addition with reversal, Google Interview
Given 2 Linked Lists containing single digit as data representing number with most significant digit at head and least significant at the tail return the addition of both.
- niklabh811 June 21, 2018
The solution must not reverse the given linked lists and do it in O(n) time complexity and constant space complexity(Recursive solution will take O(n) space because of stack).
For example:
9 -> 3 -> 2 -> 2 ->
+
3 -> 4 -> 8 -> 3 ->
=
1 -> 2 -> 8 -> 0 -> 5| Flag | PURGE 0 Answers Question
Take as input N, a number. Take N more inputs and store that in an array.
- Sagarshvn June 16, 2018
a. Write a recursive function which counts the number of ways the array could be split in two groups, so that the sum of items in both groups is equal. Each number in the array must belong to one of the two groups. Print the value returned.
b. Write a recursive function which keeps track of ways an array could be split in two groups, so that the sum of items in both groups is equal. Each number in the array must belong to one of the two groups. Return type of function should be void. Print the two groups, each time you find a successful split.
Input Format:
Take as input N, a number. Take N more inputs and store that in an array.| Flag | PURGE 0 Answers Error in 6th Edition
Maybe you fixed this already in 7th.
- timcrall January 09, 2018
In 6th edition, question 4.11, the question only specifies a binary tree but the answer assumes a binary search tree. Which is exactly a thing you told us to look out for. So I was.
EDIT: Although this doesn't really seem to affect the answer.
Also, for the love of all things holy, invest in some spam-blocking on the forums!| Flag | PURGE 0 Answers String Transformation
You are given 2 Strings A and B. You have to transform A to become B.
- anuj January 07, 2018
Following are the type of transformation possible:
1. pick an alphabet and replace all occurrences of this alphabet in the string by the next alphabet in the sequence[a,b,c,d----y,z]. Note that the next alphabet for z is a. The whole operation counts as one operation with Cost C is given as input.
2.pick an alphabet and replace all occurrences of this alphabet in the string by the previous alphabet in the sequence[a,b,c,d----y,z]. Note that the next alphabet for a is z. The whole operation counts as one operation with Cost D is given as input.
You have to return the minimum cost to transform A to B. if it's not possible return -1
Example:
A: "ab"
B: "cc"
C:2
D:5
Answer : 4
we need two C operations "ab" -->"bb"-->"cc"
Note that the last step of converting all b to c counts as one operation| Flag | PURGE 0 Answers Developing Java game
creating a RESTful service using which players can play a simple game described
- stallapp November 02, 2017
below.
The game should have the following rules:
• The player has an infinite amount of coins.
• The player bets 10 coins to play a normal game round.
• In any round (free or normal), the player has a 30% chance of winning back 20 coins.
• In any round (free or normal), the player also has a 10% chance of triggering a free round where
the player does not have to pay for bet. The free round works in the same way as a normal round except
it costs 0 coins. The free round should follow immediately after the normal round.
• The player can both win coins and free round at the same time.| Flag | PURGE 0 Answers rejected by amazon for no reason
got rejected, I think I did well for all rounds, maybe not behavioral questions. They didn't give any feedback.
- ly October 21, 2017
the questions were not hard at all.
one round, I only got asked behavioral questions for 45 mins. really not that much to say
disappointed| Flag | PURGE 0 Answers Is Amazon Joking Around?
Amazon is known for its tough tech screening rounds but even if you nail those technical question with best possible solution, are you getting screwed??
- hprem991 August 04, 2017
Before this experience, I would have said NO but now it is looking different..
I was being picked up by their recruiter and asked to present myself for phone screening as they liked my experience (thats what they said ).
Now, I wouldnt mind.. being the fact that I am doing great in what I am doing.. its just a 1 hour call.
Well, call lasted for like 55 mins.. Was asked 2 algorithmic questions with code and follow ups and some pretty team / experience related question..
I nailed the tech rounds so much that the interviewer said, I got questions done with most optimal solutions and of course before time.
So, if they liked my experiences ( thats what they said they called me at first place).. Did they rejected me for same experience or Amazon interview has become a joking ground now?
Any thoughts??| Flag | PURGE 1 Answer Design a FIDS(Flight Information Display System)
1. Consider most important classes & ignore Interfaces as of now
- AD August 04, 2017
2. FIDS is not about reservation system but the dasboard to display
3. the information will look like:
DEPARTURES
----------------------
Attributes:
STD, Airline,Flight#,Destination/Via,CheckInCounter#,Gate,Status,ETD
Values :
12:50,KingFisher,6E352,Hyderabad,A-B,23,Check-In Open,13:15
ARRIVALS
-----------------------
Attributes:
STA,Airline,Flight#,Destination/Via,Gate,Status,ETA
Values :
12:50,KingFisher,6E352,UK/Mumbai,Terminal2,Landed,13:15| Flag | PURGE 0 Answers Minheap: TLE
The following is my code for MinHeap. But it is showing TLE for some input. Can someone please help me figure out where?
- ranjani4ever July 14, 2017
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void swap(int *a,int *b){
int temp=*a;
*a=*b;
*b=temp;
return;
}
void heapify(vector<int> &heap,int index)
{
int length=heap.size();
int min=index;
int left=(index<<1)+1;
int right=(index<<1)+2;
if(left<length&&heap[left]<heap[min])
min=left;
if(right<length&&heap[right]<heap[min])
min=right;
if(min!=index)
{
swap(&heap[index],&heap[min]);
heapify(heap,min);
}
}
int main() {
int t,n;
string op;
scanf("%d",&t);
vector<int> heap;
while(t--) {
cin>>op;
//cout<<"Currently analysing"<<op<<"\n";
if(op=="insert") {
scanf("%d",&n);
heap.push_back(n);
int i=heap.size()-1;
while (i!=0&&heap[(i-1)>>1]>heap[i])
{
swap(&heap[i], &heap[(i-1)>>1]);
i =(i-1)/2;
}
}
else if(op=="getMin") {
if(heap.size()>0)
printf("%d\n",heap[0]);
else
printf("Empty\n");
/*for(int i=0;i<heap.size();i++)
cout<<heap[i]<<" ";
cout<<"\n";*/
}
else {
if(heap.size()>0)
{
heap.erase(heap.begin());
heapify(heap,0);
}
}
}
return 0;
}| Flag | PURGE 0 Answers Amazon question
At Amazon.com, users log in and access random pages numbered as 1,2,3… Given at any time, you need to tell the most popular sequence of 3 pages visited by users.
- yeswanth June 28, 2017
Eg.
At some time t,
U1: P1, P2, P3, P8, P1, P2
U2: P8, P1, P2
O/P: P8, P1, P2
At time t+1, say
U1: P1, P2, P3, P8, P1, P2, P3
U2: P8, P3, P2
O/P: P1, P2, P3| Flag | PURGE 0 Answers Question
There are around 40 million files in a directory which needs to be transferred to another system via FTP in order of oldest file first. What's the ideal way to iterate over files and store it in a data structure from where it can be transferred?
- anjesh June 12, 2017| Flag | PURGE 0 Answers qwrew
A mission-critical production system has n stages that have to be performed sequentially; stage
- tanvirmahmud201505039 June 08, 2017
i is performed by machine Mi. Each machine Mi has a probability ri of functioning reliably and
a probability 1 − ri of failing (and the failures are independent). Therefore, if we implement
each stage with a single machine, the probability that the whole system works is r1 · r2 · · · rn.
To improve this probability we add redundancy, by having mi copies of the machine Mi that
performs stage i. The probability that all mi copies fail simultaneously is only (1 − ri)mi, so the
probability that stage i is completed correctly is 1 − (1 − ri)mi and the probability that the whole
system works is Qni=1(1 − (1 − ri)mi). Each machine Mi has a cost ci, and there is a total budget
B to buy machines. (Assume that B and ci are positive integers.)
Given the probabilities r1, . . . , rn, the costs c1, . . . , cn, and the budget B, find the redundancies
m1, . . . , mn that are within the available budget and that maximize the probability that the
system works correctly| Flag | PURGE