TestVita | Code Vita 2015 | round 2

TestVita

Problem:

TCS is working on a new project called "TestVita". There are N modules in the project. Each module (i) has completion time denoted in number of hours (Hi) and may depend on other modules. If Module x depends on Module y then one needs to complete y before x.

As Project manager, you are asked to deliver the project as early as possible.
Provide an estimation of amount of time required to complete the project.
Input Format:

First line contains T, number of test cases.

For each test case: 
  1. First line contains N, number of modules.
  2. Next N lines, each contain:
    • (i) Module ID
    • (Hi) Number of hours it takes to complete the module
    • (D) Set of module ids that i depends on - integers delimited by space.

Output Format:

Output the minimum number of hours required to deliver the project.

Constraints:

1. 1 <= T <= 10
2. 0 < N < 1000; number of modules
3. 0 < i <= N; module ID 
4. 0 < Hi < 60; number of hours it takes to complete the module i
5. 0 <= |D| < N; number of dependencies
6. 0 < Dk <= N; module ID of dependencies

Sample Input and Output

SNo.InputOutput
1
1
5
1 5 0
2 6 1
3 3 2
4 2 3
5 1 3

16

Program:

#include <stdio.h>
int main() {
int n,m[10],t[10],d[10],q,a,i,sum=0;
scanf("%d",&a);
for(q=1;q<=a;q++)
{
scanf("%d",&n);
for(i=0;i<n;i++)
    scanf("%d %d %d",&m[i],&t[i],&d[i]);
    for(i=0;i<n-1;i++)
    {
            if(d[i]==d[i+1])
            {
                if(t[i]<t[i+1])
                t[i]=0;
                else
                t[i+1]=0;
            }
    }
   for(i=0;i<n;i++)
   {
       sum=sum+t[i];
   }
    printf("%d",sum);
}
return 0;
}

Output:

1
5
1 5 0
2 6 1
3 3 2
4 2 3
5 1 3

16

You can also run it on an online IDEhttps://ide.geeksforgeeks.org/eTqOGzjCr5

Your feedback are welcomed! If you have any doubts you can contact me or comment below! Cheers!

 Related Link: Bank Compare

Jumble With Numbers

Jumble With Numbers

Problem

In NASA, two researchers, Mathew and John, started their work on a new planet, but while practicing research they faced a mathematical difficulty. In order to save the time they divided their work.
So scientist Mathew worked on a piece and invented a number computed with the following formula:
A Mathew number is computed as follows using the formula:
H(n) = n(2n-1)
And scientist John invented another number which is built by the following formula which is called John number.
T(n) = n(n+1)/2
Now Mathew and John are jumbled while combining their work. Now help them combine their research work by finding out number in a given range that satisfies both properties. Using the above formula, the first few Mathew-John numbers are:
1 6 15 28 …

Input Format:

Input consists of 3 integers T1,T2,M separated by space . T1 and T2 are upper and lower limits of the range. The range is inclusive of both T1 and T2. Find Mth number in range [T1,T2] which is actually a Mathew-John number.

Line 1
T1 T2 M,where T1 is upper limit of the range, T2 is lower limit of the range and M ,where Mth element of the series is required

Constraints:

0 < T1 < T2 < 1000000

Output Format:

Print Mth number from formed sequence between T1 and T2(inclusive).

Line 1
For Valid Input,print

Print Mth number from formed sequence between T1 and T2
Or
No number is present at this index

For Invalid Input,print

Invalid Input


Sample Input and Output:


SNo.InputOutput
1               
90 150 2             
120
2
20 80 6
No number is present at this index
3
-5 3 a
Invalid Input

Program:

#include <stdio.h>
int main() {
int t1,t2,m,i,j,c=0,a,b,th[100],k=0;
scanf("%d %d %d",&t1,&t2,&m);
if(t1>0&&t2>0&&m>0)
{
for(i=1;i<=t2/2;i++)
{
    a=i*((2*i)-1);
    for(j=1;j<=t2/2;j++)
    {
        b=j*(j+1)/2;
        if((a==b)&&(a>=t1&&a<=t2))
        th[k++]=a;
    }
}
   if(k<m)
    printf("No number is present at this index");
    else
    printf("%d",th[m-1]);
}
         else
         printf("Invalid Input");
return 0;
}

Output:

90 150 2

120

You can also run this in online IDE: https://ide.geeksforgeeks.org/ZndEODl1gU

Your comments and feedbacks are welcomed! If you have any doubts you can leave it on the comment! Cheers!!

Related Links: Test vita

Consecutive Prime Sum | Code Vita 2016 | round 1

Problem Description:

Some prime numbers can be expressed as Sum of other consecutive prime numbers.
For example

5 = 2 + 3
17 = 2 + 3 + 5 + 7
41 = 2 + 3 + 5 + 7 + 11 + 13

Your task is to find out how many prime numbers which satisfy this property are present in the range 3 to N subject to a constraint that summation should always start with number 2.
Write code to find out number of prime numbers that satisfy the above mentioned property in a given range.

Input Format:
First line contains a number N
Output Format:
Print the total number of all such prime numbers which are less than or equal to N.
Sample Input and Output


SNo.InputOutputComment
1202
(Below 20, there are 2 such numbers: 5 and 17).
5=2+3
17=2+3+5+7
2151

Program:

#include <stdio.h>
int prime(int b)
{
    int j,cnt;
   cnt=1;
     for(j=2;j<=b/2;j++)
     {
         if(b%j==0)
         cnt=0;
     }
     if(cnt==0)
     return 1;
     else
     return 0;
}
int main() {
 int i,j,n,cnt,a[25],c,sum=0,count=0,k=0;
 scanf("%d",&n);
 for(i=2;i<=n;i++)
 {
     cnt=1;
     for(j=2;j<=n/2;j++)
     {
         if(i%j==0)
         cnt=0;
     }
     if(cnt==1)
     {
        a[k]=i;
        k++;
        }
 }
 for(i=0;i<k;i++)
 {
     sum=sum+a[i];
    c= prime(sum);
    if(c==1)
    count++;
 }
 printf("%d",count);
 return 0;
}

Output:

20

2

You can also run it on a online IDEhttps://ide.geeksforgeeks.org/XcOKzTd4Ik
If you have any doubt you can contact me or comment it below! Your comments and feedbacks are also welcomed!! Cheers!!

Related Links: Jumble with Numbers

Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution

 Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...