Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,440 views
You are given two integers as input "N" and "M" .

You have to distribute "M" candies to "N" children such that each one of them gets atleast one candy after the distribution.

Also , each child should get equal number of candies.

Find maximum number of candies each child can get .

If its not possible to do so , print -1.

Input :

N = 2

M = 5

Output :

2 (You have 5 candies . You can distribute 2 candies to the first child and 2 candies to the second child(you will still be left with one candy and thats fine))

Link to original problem for submitting : https://www.hackerrank.com/contests/desiqna-oa-practice-contest-00/challenges/a-324
in Online Assessments by Expert (108,110 points)
edited by | 1,440 views

1 Answer

0 like 0 dislike
C++ code solution : 

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll ; 

int main() {
    ll n,m ;
    cin>>n>>m ; 
    ll g = m/n ;
    if(g==0){
        g = -1;
    }
    cout<<g ; 

    return 0;
}
by Expert (108,110 points)