Question 5: HR issues
HR issues
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 -:
Shovon is an HR in a renowned company and he is assigning people to work. Now he is assigning people work in a fashion where if he assigns somework a work of cost 2, the next person will be strictly getting a job with cost equal or more than 2. Given that Shovon’s company has infinite work and a number of employees, how many distributions can be possible. The cost of jobs can go 0 to 9.
Function Description:
Complete the special_numbers function in the editor below. It has the following parameter(s):
Parameters:
Name | Type | Description |
N | Integer | The number of depts. |
arr[ ] | Integer array | The number of employees in each dept.. |
Return:
The function must return an INTEGER denoting the sum of answers for all distinct distributions.
Constraints:
- 1 <= n <= 100
- 1 <= arr[i] <= 200
Sample Cases:
Sample Input 1
2
4
1Sample Output 1
725Description
The ans if m = 1 is 1o, which is all numbers from 0 to 9
The ans for m = 2 is 55
The answer for m = 3 is 220
The answer for m = 4 is 715
So fun(4) + fun(1) = 725
C++
Python
Java
C++
#include <bits/stdc++.h>
using namespace std;
int func(int s,int p,int n)
{
if(p==n-1) return 1;
int ans=0;
for(int i=s;i<=9;i++)
ans+=func(i,p+1,n);
return ans;
}
int main()
{
int n,a, ans=0;
cin>>n;
vector<int> v(n);
for(int i=0;i<n;i++)
{
cin>>a;
for(int i=0;i<=9;i++)
ans+=func(i,0,a);
}
cout<<ans;
}
Python
n=int(input())
a1=[]
for i in range(n):
a1.append(int(input()))
dp=[0]*201
dp[1]=10
dp[2]=55
a=[1]*10
i=3
while i<201:
s=0
for i1 in range(10):
s+=a[i1]
a[i1]=s
dp[i]+=(s*(10-i1))
dp[i]=dp[i]%((10**9)+7)
i+=1
s1=0
for i in a1:
s1+=dp[i]
s1=s1%((10**9)+7)
print(s1)
Java
import java.util.*;
class Main
{
static int func(int s,int p,int n)
{
if(p==n-1) return 1;
int ans=0;
for(int i=s;i<=9;i++)
ans += func(i,p+1,n);
return ans;
}
public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
int n = sc.nextInt ();
int ans=0;
for(int i=0; i<n; i++){
int a = sc.nextInt ();
for(int j=0; j<=9; j++)
ans+=func(j,0,a);
}
System.out.println (ans);
}
}
Login/Signup to comment