Joining Date CodeChef Solution

Problem – Joining Date CodeChef Solution

N candidates (numbered from 1 to N) join Chef’s firm. The first 5 candidates join on the first day, and then, on every subsequent day, the next 5 candidates join in.
For example, if there are 12 candidates, candidates numbered 1 to 5 will join on day 1, candidates numbered 6 to 10 on day 2 and the remaining 2 candidates will join on day 3.

Candidate numbered K decided to turn down his offer and thus, Chef adjusts the position by shifting up all the higher numbered candidates. This leads to a change in the joining day of some of the candidates.

Help Chef determine the number of candidates who will join on a different day than expected.

Input Format

  • First line will contain T, number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, two space-separated integers N and K denoting the number of candidates and the candidate who turned down the offer.

Output Format

For each test case, output a single integer denoting the number of candidates whose joining day will be changed.

Constraints

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

Sample 1:

Input:
4
7 3
6 6
2 1
14 2
Output:
1
0
0
2

Explanation:

Test case 1: The original joining day of each candidate is given as [1,1,1,1,1,2,2] but as candidate 3 turns down his offer, the new joining days are now [1,1,NA,1,1,1,2]. Candidate numbered 6 is the only one to have his joining day changed.

Test case 2: The original joining day of each candidate is given as [1,1,1,1,1,2] but as candidate 6 turns down his offer, the new joining days are now [1,1,1,1,1,NA]. No candidate got his joining day changed.

Test case 3: The original joining day of each candidate is given as [1,1] but as candidate 1 turns down his offer, the new joining days are now [NA,1]. No candidate got his joining day changed.

Test case 4: The original joining day of each candidate is given as [1,1,1,1,1,2,2,2,2,2,3,3,3,3] but as candidate 2 turns down his offer, the new joining days are now [1,NA,1,1,1,1,2,2,2,2,2,3,3,3]. Candidate numbered 6 and 11 are the only ones to have their joining days changed.

Joining Date 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
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int i=0;i<t;i++){
		    int n = sc.nextInt();
		    int k = sc.nextInt();
		    int temp = ((n-1)/5 - (k-1)/5);
		    System.out.println(temp);
		}
	}
}

Joining Date CodeChef Solution in C++14

#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int a,b;
	    cin>>a>>b;
	    int k=a/5;
	    if(a%5!=0)
	    {
	        k++;
	    }
	    int j=b/5;
	    if(b%5!=0)
	    {
	        j++;
	    }
	    cout<<k-j<<endl;
}

int main() {
    
    int t;
    cin>>t;
    
    while(t--)
    {
        solve();
    }
	
	return 0;
}

Joining Date CodeChef Solution in Pyth 3

# cook your dish here
for _ in range(int(input())):
    x,y=map(int,input().split())
    p=x//5
    if x%5==0:
        p-=1 
    q=y//5
    if y%5==0:
        q-=1 
    print(p-q)
Joining Date CodeChef Solution Review:

In our experience, we suggest you solve this Joining Date 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 Joining Date CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Joining Date 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 *