HackerRank Coding Question for Placements 6

A man starts from his house with a few pan cakes. let they be N. Now he visits K places before reaching home. At each place he can buy a cake, sell a cake or do nothing. But he must sell L cakes before reaching home.Find the maximum number of cakes he can have at any point in his journey.N,K,L are given as input?

Please comment down the solutions, we will add them here.

4 comments on “HackerRank Coding Question for Placements 6”


  • Ruturaj

    def count(n,m):
    arr = [0]*n
    i=0
    while(sum(arr)!=4):
    if arr[i]==1:
    return(‘NO ‘+str(sum(arr)))
    break
    else:
    arr[i]+=1
    i = m+i
    if i>=n:
    i = i-n
    return(‘YES’)


  • Amay Dubey

    If all N robots have a cake, output “Yes” (without quotes).
    Otherwise, output “No” (without quotes) followed by a space and the number of robots which have a cake.

    Input
    The first line of input contains a single integer T denoting the number of test cases.
    The single line of each test cases contains two space separated integers N and M.

    Example
    Input:
    3
    2 0
    2 1
    4 2

    Output:
    No 1
    Yes
    No 2


    • Amay Dubey

      Example
      Input:
      3
      2 0
      2 1
      4 2

      Output:
      No 1
      Yes
      No 2

      Output
      For each of the T test cases, output a single line:

      If all N robots have a cake, output “Yes” (without quotes).
      Otherwise, output “No” (without quotes) followed by a space and the number of robots which have a cake.

      Input
      The first line of input contains a single integer T denoting the number of test cases.
      The single line of each test cases contains two space separated integers N and M