Most Cost Efficient Car Problem Statement

Given the cost and operational details for both 'Petrol' and 'Diesel' cars, determine which type is more cost-efficient for a period of exactly 6 months. Output an integer indicating the result: '0' for Petrol car, '1' for Diesel car, and '-1' if both are equally efficient.

Explanation:

You will be provided with details such as price, monthly maintenance cost, kilometers per liter, fuel price per liter, and kilometers driven per month for both Petrol and Diesel cars. Calculate the total cost for a 6-month period for both cars to decide the most cost-efficient option.

Input:

The first line contains an integer ‘T’ representing the number of test cases.

For each test case, the next two lines contain space-separated integers:
1. For the Petrol car: Price, maintenance cost per month, km per liter, fuel price per liter, km per month.
2. For the Diesel car: Price, maintenance cost per month, km per liter, fuel price per liter, km per month.

Output:

For each test case, output '0' if Petrol is more efficient, '1' if Diesel is more efficient, or '-1' if both are equally efficient.

Example:

Input:
1
780000 500 35 75 145
850000 1000 30 80 200

Output:
0

Constraints:

  • 1 <= T <= 10^5
  • 1 <= priceOfCar, maintenanceCostPerMonth, numberOfkilometerCarRunInOneLiter, pricePerLiter, numberOfKilometerCarRunInaMonth <= 10^9
  • Time Limit: 1 second

Note:

Implementation should focus on efficiency due to potentially high constraints.

AnswerBot
4mo

Determine the most cost-efficient car (Petrol or Diesel) for a 6-month period based on given details.

  • Calculate total cost for 6 months for both Petrol and Diesel cars

  • Compare the total costs to determi...read more

Help your peers!
Select
Add answer anonymously...
TCS System Engineer Specialist Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits