Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Minimum Cars required CodeChef Solution

Problem – Minimum Cars required CodeChef Solution

A single car can accommodate at most 4 people.

N friends want to go to a restaurant for a party. Find the minimum number of cars required to accommodate all the friends.

Input Format

  • The first line contains a single integer T – the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains an integer N – denoting the number of friends.

Output Format

For each test case, output the minimum number of cars required to accommodate all the friends.

Constraints

  • 1≤T≤1000
  • 2≤N≤1000

Sample 1:

Input: 4
4
2
7
98
Output: 1
1
2
25

Explanation:

Test Case 1: There are only 4 friends and a single car can accommodate 4 people. Thus, only 1 car is required.

Test Case 2: There are only 2 friends and a single car can accommodate 4 people. Thus, only 1 car is required

Test Case 3: There are 7 friends and 2 cars can accommodate 8 people. Thus, 2 cars are required.

Minimum Cars required CodeChef Solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	    Scanner sc=new Scanner(System.in);
	    int T=sc.nextInt();
	    for(int i=0;i<T;i++)
	    {
		int x=sc.nextInt();
		int a=x%4;
		int b=x/4;
		if(a==0)
		System.out.println(b);
		else
		System.out.println(b+1);
	    }
	}
}

Minimum Cars required CodeChef Solution in Pyth 3

# cook your dish here
n=int(input())
for i in range(0,n):
    e=int(input())
    d=e%4
    if(d<4 and d!=0):
        print((e//4)+1)
    elif(d==0):
        print(e//4)
        

Minimum Cars required CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n;
	    cin>>n;
	   // cout<<n*2<<endl;
	   if(n%4==0)
	    {
	        cout<<(n/4)<<endl;
	    }
	    else{
	        cout<<(n/4)+1<<endl;
	    }
	}

	return 0;
}
Minimum Cars required CodeChef Solution Review:

In our experience, we suggest you solve this Minimum Cars required CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Minimum Cars required CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Minimum Cars required CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *