## Forum Posts

- 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 - 0 Answers
**Designing a data-structure**We need to implement a data-structure for following functions

- arnav251035 May 29, 2017

Insert X : Insert an element X into the set.

Delete X : Delete an element X from the set. It is guaranteed that such X always exist in the data structure.

Mean : Report Mean of the elements present in the data set. It is guaranteed that data structure will not be empty at this query.

Mode : Report Mode of the elements present in the data set. It is guaranteed that data structure will not be empty at this query.

Median : Report Median of the elements present in the data set. It is guaranteed that data structure will not be empty at this query

I had created a linked list of the values, and like insertion sort I inserted the elements in the Linked List. Deletion was also the same as deletion in Linked List. Mean I calculated on the run as and when the values came. For mode I traversed the whole linked list to see which element occurs the most. Median was the middle element in the linked list.

I know there is an efficient algorithm to calculate median on the run using two heaps (min and max) but calculating mode was the biggest problem I faced. The number of queries ranged to 10^5 and the time limit was given 3 secs. Had a TLE error| Flag | PURGE - 0 Answers
**6 to 8 months project ideas to build up résumé**Hello,

- otto.alyz April 18, 2017

I'm planning to go through big IT companies interviews (basically the GAFAs) in 8 months from now, and I would like to get some suggestions about ideas of projects I can work on to present during my interviews and build up my résumé.

I ideally looking for a project that would make me practice the OOP principles like SOLID, as well as other things like scalability, algorithms and data structures and so on.

Thanks in advance for your suggestions.| Flag | PURGE - 0 Answers
**Amazon Rejection**Hi All,

- mourya.rohit32 April 10, 2017

The day before yesterday, I got rejected from Amazon in the final round for SDE-T. Though I was more interested in SDE.

All the rounds were quite easy for me and I solved all the questions. However in the last round, I knew both the questions but failed to arrive to a good solution. I knew the correct data structure which can be used to get O(n) solution however, I failed to code it and thus I was eliminated.

My question is, are there any chances for getting call from Amazon based on my interview answers for SDE in future or I've to wait for 6 months and again apply for SDE position.?

Any response would be welcome.

Thanks,

Rohit| Flag | PURGE - 0 Answers
**Request for assistance - Was interviewed by Amazon no information after telephonic round**Hi there,

- Madhulika.NYC April 03, 2017

I was interviewed by Amazon. I thought I did very well in the telephonic round. I think the interview went on for more than an hour. The interviewer did say that someone will contact me, but no one had contacted me since then.

When I checked my status at amazon job application site it shows Accepted - In Progress. I don't know how long to wait for.

Could someone please assist me?| Flag | PURGE - 0 Answers
**algorithm**the maximum number of pebbles collected when you move from cell-(1,1) to cell -(4,5) is 127 and the path that leads to it is given by:(1,1)->(2,1)->(3,2)->(4,3)->(4,4)->(4,5)

- enfield.12biker March 26, 2017

write an algorithm to find maximum pebbles while going from cell -(1,1) to cell -(m,n| Flag | PURGE - 0 Answers
**Sab labs programming question**You have developed an e-commerce website,SHOPPY.Many people have created accounts at your website.you have the passwords of all the users.you want to know how many distinct password =s are there in total.Details of the passwords are as described:

- premjeetsingh6288 February 28, 2017

Each password is a string of characters from a to z

Two passwords, say pass1 and pass2 are said to be same if pass2 can be obtained by swapping the ith character in pass1 where (i+j)%2=0

Input:

input1:N,number of users registered input2[]:Array of strings containing all passwords of the N users.

Output: return T total number of distinct password present

Example: input:2,{abcd,cdab}

output: 1

input:2,{abcd,bcad}

output: 2| Flag | PURGE

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window