Fill the Bucket CodeChef Solution

Problem – Fill the Bucket CodeChef Solution

Chef has a bucket having a capacity of K liters. It is already filled with X liters of water.

Find the maximum amount of extra water in liters that Chef can fill in the bucket without overflowing.

Input Format

  • The first line will contain T – the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains two space separated integers K and X – as mentioned in the problem.

Output Format

For each test case, output in a single line, the amount of extra water in liters that Chef can fill in the bucket without overflowing.

Constraints

  • 1≤T≤100
  • 1≤X<K≤1000

Sample 1:

Input: 2
5 4
15 6
Output: 1
9

Explanation:

Test Case 1: The capacity of the bucket is 5 liters but it is already filled with 4 liters of water. Adding 1 more liter of water to the bucket fills it to (4+1)=5 liters. If we try to fill more water, it will overflow.

Test Case 2: The capacity of the bucket is 15 liters but it is already filled with 66 liters of water. Adding 9 more liters of water to the bucket fills it to (6+9)=15 liters. If we try to fill more water, it will overflow.

Fill the Bucket CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
    int t,k,x;
    cin>>t;
    while(t--){
        cin>>k>>x;
        cout<<k-x<<endl;
    }
	return 0;
}

Fill the Bucket CodeChef Solution in Java

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

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		for(int i=0;i<n;i++){
		    int a=in.nextInt();
		    int b=in.nextInt();
		    if(a>=b){
		        System.out.println(a-b);
		    }
		    else {
		        System.out.println(b-a);
		    }
		}
	}
}

Fill the Bucket CodeChef Solution in Pyth 3

t = int(input())
for i in range(t):
    k,x = list(map(int,input().split()))
    print(k-x)
Fill the Bucket CodeChef Solution Review:

In our experience, we suggest you solve this Fill the Bucket 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 Fill the Bucket CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Fill the Bucket 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.