Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike

2 Answers

0 like 0 dislike
 
Best answer

Q1. Magic Parent
A person X has M different flavor of candies(An array of size M was given with quantity of each candy of particular flavor) and there are N childrens, X has to distribute maximum number of candies among children and every child has the condition that it will only take candies of a particular flavor only ( it is also possible that child may not take any candy at all) and also the other children will get jealous if some children get maximum candies, you have to find the minimum jealously( maximum amount of candy given to a child/children ).

 

T.C:- N=7 M=5
flavors=[2,6,6,4,4];
ans:- 4
Disribution of candies was like :- 2,3,3,4,4,3,3

 

 

by Expert (44,360 points)
0 like 0 dislike

1)binary search

 




def envylevel(N,M,arr):
    import math
    def helper(k):
        count=0
        for i in arr:
            count+=math.ceil(i/k)

        return count<=N
    l=0
    r=max(arr)
    ans=-1
    while l<=r:
        mid=(l+r)//2
        if helper(mid):
            r=mid-1
            ans=mid
        else:
            l=mid+1
    return (ans)
by Expert (44,360 points)
...