Practo Interview Question for Software Developers


Country: India
Interview Type: Written Test




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

d = (d1 + d2) > d3) ? (d1 + d2 + d3) : (d1 + d2 + Math.min(d1, d2))

- Ling February 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public static void main(String[] args) {
		int d1,d2,d3,min;
		Scanner scan =new Scanner(System.in);
		
		System.out.println("Enter the Distance from home to shop1");
		d1= scan.nextInt();
		
		System.out.println("Enter the Distance from home to shop2");
		d2=scan.nextInt();
		
		System.out.println("Enter the Distance between shops");
		d3=scan.nextInt();
		
		int a=(2*(d1+d3));
		//System.out.println(a);
		int b=d1+d2+d3;
		//System.out.println(b);
		
		
		min=(a<b) ? (a) : (b);
				System.out.println("The minimum distance traveled by the man is" + min);
	}

- dhruv February 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The whole distance will be contains:
1) way from home to the 1st shop (d1)
2) way from the 2nd shop to home (d2)
3) minimal way from the 1st shop to the 2nd one (directly - d3, or through the home d1+d2)

holeWay = d1 + d2 + Math.min(d1+d2, d3)

- Maxim February 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In the first example the output can be less than 4 (3 = go from home to the 1st (1) + go from the 1st to the 2nd (1) + got from the 2nd, to the home (1)).

- Maxim February 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
public static void main(String[] args) {
int d1,d2,d3,min;
Scanner scan =new Scanner(System.in);

System.out.println("Enter the Distance from home to shop1");
d1= scan.nextInt();

System.out.println("Enter the Distance from home to shop2");
d2=scan.nextInt();

System.out.println("Enter the Distance between shops");
d3=scan.nextInt();

int a=(2*(d1+d3));
//System.out.println(a);
int b=d1+d2+d3;
//System.out.println(b);


min=(a<b) ? (a) : (b);
System.out.println("The minimum distance travelled by the man is" + min);
}

}

- dhruv February 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{{{{ public static void main(String[] args) { int d1,d2,d3,min; Scanner scan =new Scanner(System.in); System.out.println("Enter the Distance from home to shop1"); d1= scan.nextInt(); System.out.println("Enter the Distance from home to shop2"); d2=scan.nextInt(); System.out.println("Enter the Distance between shops"); d3=scan.nextInt(); int a=(2*(d1+d3)); //System.out.println(a); int b=d1+d2+d3; //System.out.println(b); min=(a<b) ? (a) : (b); System.out.println("The minimum distance travelled by the man is" + min); } }}}}}} - dhruv February 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
class Main
{
public static void main(String[] args)
{
int d1,d2,d3,min;
Scanner scan=new Scanner(System.in);
System.out.println("enter distace to shop1");
d1=scan.nextInt();
System.out.println("enter distance to shop2");
d2=scan.nextInt();
System.out.println("enter distance between two shops");
d3=scan.nextInt();
int a=2*(d1+d3);
int b=2*(d1+d2);
int c=d1+d2+d3;
int d=2*(d2+d3);
if(a<=b&&a<=c&&a<=d){
min=a;
System.out.println("min distance is :"+min);
}
else if(b<=a&&b<=c&&b<=d)
{
min=b;
System.out.println("min distance is :"+min);
}
else if(c<=a&&c<=b&&c<=d)
{
min=c;
System.out.println("min distance is :"+min);
}
else
{
min=d;
System.out.println("min distance is :"+ min);
}
}
}

- Rohan nirer September 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
class Test
{
public static void main(String[] args)
{
int d1,d2,d3,min;

Scanner scan=new Scanner(System.in);
System.out.println("enter distace to shop1");
d1=scan.nextInt();
System.out.println("enter distance to shop2");
d2=scan.nextInt();
System.out.println("enter distance between two shops");
d3=scan.nextInt();

int a=d1+d2;
int b=d2+d3;
int c=d1+d3;

if(a<=b && a<=c){
min=a*2;
System.out.println("min distance is :"+min);
}else
if(b<=a && b<=c){
min=a*2;
System.out.println("min distance is :"+min);
}else
{
min=c*2;
System.out.println("min distance is :"+min);
}
}
}

- Adithya September 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Int X[]={d1,d2,d3};
Arrays.sort(x);
Minimumdistance=2*(X[0]+X[1]);
System.out.print(Minimumdistance);

- Manikandan September 07, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ji

- Manikandan September 07, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
int main() {

int d1, d2, d3, minimum_distance=0,i;
int a[4];
scanf("%d %d %d", &d1, &d2, &d3);

a[0]=d1+d2+d3;
a[1]=2*(d1+d2);
a[2]=2*(d1+d3);
a[3]=2*(d2+d3);
minimum_distance=a[0];
for(i=0;i<4;i++)
{
if(minimum_distance>a[i])
minimum_distance=a[i];
}

printf("%d", minimum_distance);
printf("\n");
return 0;
}

test cases
input output
10 20 30 60
1 1 5 4

- vishnu vardhan September 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

0
of 0 vote
Int X[]={d1,d2,d3};
Arrays.sort(x);
If(d1==d2&&d2==d3)
{
Minimumdistance=d1+d2+d3;
}else
{
Minimumdistance=2*(X[0]+X[1]);
}
System.out.print(Minimumdistance);

- Mani September 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

wholeWay = d1 + d2 + Math.min(d1+d2, d3)

- Maxim February 15, 2017 | 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