Can You Eat It CodeChef Solution

Problem – Can You Eat It CodeChef Solution

You are a person who is always fond of eating candies. Your friend gave you a candy of length N, to eat during the break period of your school.

You start eating this candy from one of the ends. But as it is not your candy, your friend told you to eat exactly K unit length of candy during each bite. You will stop eating if the candy’s length becomes 0. This means that you have eaten the entire candy.

If at some point of time, the candy’s length is positive, but less than K, you cannot take a bite thereafter.

Can you eat the complete candy? If yes, print the number bites it will take, else print −1.

Input Format

  • First line will contain T, number of testcases. Then the testcases follow.
  • Each testcase contains of two spaced integers NK.

Output Format

For each testcase, print the minimum number of bites you need to eat the complete candy. Print −1 if it is not possible to do so.


  • 1≤T≤10^5
  • 0≤N≤10^6
  • 1≤K≤10^6

Sample 1:

3 1
3 2
0 3


Test case 1: When you eat your first bite of length 1, the length of the candy will become 2. After the second bite, the candy’s length will be 1 and finally after the third bite, candy’s length will be 0, and hence you eat the entire candy!

Test case 2: After the first bite, candy’s length will become 1. You cannot go for the second bite as candy’s length is positive and less than 2.

Test case 3: Candy’s length is already 0, hence it can be said that you have eaten the entire candy!

Can You Eat It CodeChef Solution in Java

import java.util.Scanner;

class CanYouEatIt {
    static void myMethod(int N, int K){
        else if(N==0){
    public static void main(String[] args) {
        Scanner scan = new Scanner(;
        int T=scan.nextInt();
            int N=scan.nextInt();
            int K=scan.nextInt();
            myMethod(N, K);

Can You Eat It CodeChef Solution in Pyth 3

# cook your dish here
t = int(input())
for i in range(0,t):
    n,k = map(int,input().split())
    if n%k ==0: print(int(n/k))
    else: print(-1)

Can You Eat It CodeChef Solution in C++14

#include <iostream>
using namespace std;

int main() {
	int t;
	    int n,x;
	return 0;
Can You Eat It CodeChef Solution Review:

In our experience, we suggest you solve this Can You Eat It 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 Can You Eat It CodeChef Solution

Find on CodeChef


I hope this Can You Eat It 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 *