# Question-1 Biggest Meatball # Biggest Meatball

In this article we will see InfyTQ Sample Coding question. You will find solution of InfyTQ Coding question in different programming language on this page.

## Problem Statement

Bhojon is a restaurant company and has started a new wing in a city. They have every type of cook except the meatball artist. They had fired their last cook because the sale of meatballs in their restaurant is really great, and they can’t afford to make meatballs again and again every time their stock gets empty. They have arranged a hiring program, where you can apply with their meatball.
They will add the meatball in their seekh (a queue) and everytime they cut the meatball they take it and cut it on the day’s quantity and then re-add the meatball in the seekh. You are the hiring manager there and you are going to say who is gonna be hired.

Day’s quantity means, on that very day the company sells only that kg of meatballs to every packet.

If someone has less than a day’s quantity, it will be counted as a sell.

### Function Description:

• Complete the function with the following parameters:

### Parameters:

 Name Type Description N Integer How many people are participating in the hiring process. D Integer Day’s quantity, how many grams of meatball is being sold    to every packet. Array[ ] Integer array Array of integers, the weight of meatballs everyone came with.

### Return:

• The ith person whose meat is served at last.

### Constraints:

• 1 <= N <= 10^3
• 1 <= D <= 10^3
• 1 <= Array[i] <= 10^3

### Input Format:

• First line contains N.
• Second line contains D.
• After that N lines contain The ith person’s meatball weight.

### Output Format:

The 1 based index of the man whose meatball is served at the last.

4

2

[7 8 9 3]

3

### Explanation:

The seekh or meatball queue has [7 8 9 3] this distribution. At the first serving they will cut 2 kgs of meatball from the first meatball and add it to the last of the seekh, so after 1st time it is:

[8 9 3 5]

Then, it is: [9 3 5 6],  [3 5 6 7], [5 6 7 1], [6 7 1 3], [7 1 3 4], [1 3 4 5], [3 4 5], [4 5 1], [5 1 2], [1 2 3], [2 3], , , 

So the last served meatball belongs to the 3rd person.

`#include <bits/stdc++.h>using namespace std;int main(){    int n,x,a,m=0,maxPos=0;    cin>>n;    vector<int> v(n);    cin>>x;        for(int i=0;i<n;i++){        cin>>v[i];    }        for(int i=0;i<n;i++){        v[i]=(v[i]-1)/x;            }     for(int i=0;i<n;i++){                if(v[i]>=m){            m=v[i];            maxPos=i;        }    }        cout<<maxPos+1;}`
`n=int(input())m=0mxPos=0v=*nx=int(input())for i in range(n):    v[i]=int(input())for i in range(n):    v[i]=(v[i]-1)//xfor i in range(n):    if v[i]>=m:        m=v[i]        mxPos=iprint(mxPos+1)`
`import java.util.*;class Main{   public static void main(String args[])  {    Scanner sc = new Scanner (System.in);        int n=sc.nextInt();    int v[]= new int[n];    int x=sc.nextInt();       for(int i=0; i<n; i++)       v[i]=sc.nextInt();        for(int i=0;i<n;i++){        v[i]=(v[i]-1)/x;            }        int m=0, maxPos=0;        for(int i=0;i<n;i++){                if(v[i]>=m){            m=v[i];            maxPos=i;        }    }        System.out.println(maxPos+1);  } }`

### 7 comments on “Question-1 Biggest Meatball”

• 3109

def get_last(n,d,balls):
completed = []
index = -1

while len(completed)<n:
index = (index+1)%n

if balls[index] <= 0:
continue

balls[index] -= d
if balls[index]<= 0:
completed.append(index)

return completed[-1]+1

if __name__ == "__main__":
n = int(input().strip())
d = int(input().strip())
balls = list(map(int,input().strip().split(" ")))

print(get_last(n,d,balls)) 0
• Mummana

Python 0
• Vignesh

Java 0
• ajithditto

n = 4
v = [8,9,2,5]
temp = [8,9,2,5]
x = 2
front = 0

for i in range(n):
v[front] = v[i] – x
rear = front
front +=1
if(v[rear] < x):
break
print(temp[rear]) 0
• Chirumamilla

def meat(x,c):
if len(x)==1:
print(x)
else:
k=x.pop(0)
k-=c
if k>0:
x.append(k)
meat(x,c)

n=int(input())
c=int(input())
arr=list(map(int,input().split()))
p=meat(arr,c) 0
• Yogesh

Python 19
• 20215a0514

Python 0