Practo Interview Question for SDE1s


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

#include

- Anonymous September 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<stdlib.h>
#define MAX 100

float expected_price(int , int *, float *);
int databases;

int main(void)
{
int n, *quantity, i;
float *price, p;

// printf("Enter number of old database:");
scanf("%d", &databases);
quantity = (int *)malloc(n * sizeof(int));
price = (float *)malloc(n * sizeof(int));
// printf("Enter quantity:");
for(i=0; i<databases; i++)
scanf("%d", &quantity[i]);
// printf("Enter price:");
for(i=0; i<databases; i++)
scanf("%f", &price[i]);
// printf("\nEnter n:");
scanf("%d", &n);
p = expected_price(n, quantity, price);
printf("\nExpected price: %.2f", p);
getchar();
free(quantity);
free(price);
return 0;
}

float expected_price(int n, int *quantity, float *price)
{
int i;
float exp_price;
for(i=0; i<databases; i++)
{
if(n == quantity[i])
{
return price[i];
}
}
if(quantity[0] < n && n < quantity[databases-1])
{
for(i=0; i<databases; i++)
{
if(quantity[i] < n && n < quantity[i+1])
{
exp_price = price[i] + ((price[i]-price[i+1])/(quantity[i]-quantity[i+1]))*(n-quantity[i]);
// x: quantity
// y: price
//y = y1+(y1-y2)/(x1-x2)*(x-x1)
}
}
}
// PHir kabhi
else if(quantity[0] > n)
{
}

else
{
// x: quantity
// y: price
//y(x)=y1+((x−x1)/(x2−x1))*(y2−y1)
exp_price = price[databases-2] + ((float)(n-quantity[databases-2])/(quantity[databases-1]-quantity[databases-2]))*(price[databases-1]-price[databases-2]);
}
return exp_price;
}

- Anonymous September 03, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More