TCS Codevita Previous Year Question & Answers | TCS CodeVita Previous Year Coding Questions | TCS Codevita Previous Papers With Answers | TCS Codevita Pre-Qualifier Round Questions | TCS CodeVita Previous Year Coding Questions & Answers
TCS Codevita Previous Year Question & Answers 2024: The coding test is medium complexity, meaning that while passing it is not impossible, it is also not very simple. If you practiced some of the code questions from the previous year’s examination, you would undoubtedly have an advantage in the upcoming TCS Codevita exam. Let’s look at a few test patterns, TCS Codevita MCQ Questions and Answers/ TCS Codevita MCQ Questions in Python, C, C++, Java, and Python code problems and their fixes. In the below section, you can find the TCS Codevita Exam Questions and Answers/ TCS Codevita Coding Questions & Answers 2023
Previous recruiting campaigns’ coding examinations placed a strong focus on arrays and other fundamental programming principles. One can easily pass the first round and even the ones after that if they prepare adequately. You must select a language that you are comfortable with, such as C, C++, Java, or even Python, in order to complete the coding tasks. More details like TCS Codevita Coding Questions and Answers, TCS Codevita Solved Questions & Answers, TCS Codevita Zone Wise Questions & Answers, TCS Codevita Questions & Answers, etc. available on its website
TCS Codevita Previous Year Question With Answers 2024
Java Program for Football League Problem
Football League Table Statement : All major football leagues have big league tables. Whenever a new match is played, the league table is updated to show the current rankings (based on Scores, Goals For (GF), Goals Against (GA)). Given the results of a few matches among teams, write a program to print all the names of the teams in ascending order (Leader at the top and Laggard at the bottom) based on their rankings.
Rules:
A win results in 2 points, a draw results in 1 point an
d a loss is worth 0 points. The team with the most goals in a match wins the match. Goal Difference (GD) is calculated as Goals For (GF) Goals Against (GA). Teams can play a maximum of two matches against each other Home and Away matches respectively.
The ranking is decided as follows: Team with maximum points is ranked 1 and minimum points is placed last Ties are broken as follows Teams with same points are ranked according to Goal Difference(GD).
If Goal Difference(GD) is the same, the team with higher Goals For is ranked ahead
If GF is same, the teams should be at the same rank but they should be printed in case-insensitive alphabetic according to the team names. More than 2 matches of same teams, should be considered as Invalid Input.
A team can’t play matches against itself, hence if team names are same for a given match, it should be considered Invalid Input
Input Format:
First line of input will contain number of teams (N) Second line contains names of the teams (Na) delimited by a whitespace character Third line contains number of matches (M) for which results are available Next M lines contain a match information tuple {T1 T2 S1 S2}, where tuple is comprised of the following information
- T1 Name of the first team
- T2 Name of the second team
- S1 Goals scored by the first team
- S2 Goals scored by the second team
Output Format:
Team names in order of their rankings, one team per line OR Print “Invalid Input” where appropriate.
Constraints:
0< N <=10,000 0<=S1,S2
Example:
Consider 5 teams Spain, England, France, Italy and Germany with the following fixtures:
- Match 1: Spain vs. England (2-0) (Spain gets 2 points, England gets 0)
- Match 2: England vs. France (1-1) (England gets 1 point, France gets 1)
- Match 3: Spain vs. France (0-2) (Spain gets 0 points, France gets 2)
Table 1. Points Table after 3 matches
Team Name | Matches Played | Goals for | Goals Against | Goal Difference | Points | Ranking |
---|---|---|---|---|---|---|
Spain | 2 | 3 | 2 | 1 | 2 | 2 |
England | 2 | 1 | 4 | -3 | 1 | 3 |
France | 2 | 3 | 1 | 2 | 3 | 1 |
Italy | 0 | 0 | 0 | 0 | 0 | 4 |
Germany | 0 | 0 | 0 | 0 | 0 | 4 |
PROGRAM
import java.util.Scanner; public class Main { public static void main(String[] args) { int n,m,i,j,k; int x=0; Scanner sc =new Scanner(System.in); System.out.println("\n\n"); System.out.println("Enter no of teams"); n = sc.nextInt(); String[] z = new String[n]; System.out.println("\n\n"); System.out.println("Enter names of Teams:"); for (i = 0; i < n; i++) { z[i]=sc.next(); } System.out.println("\n\n"); System.out.println("Enter no of matches"); m=sc.nextInt(); int[] pt = new int[n]; int[] gf = new int[n]; int[] ga = new int[n]; int[] gd = new int[n]; int[] mt = new int[n]; String[] s = new String[n+n]; String[][] a = new String[m][]; System.out.println("\n\n"); System.out.println("Enter details of matches (Team1 Team2 T1 T2goals)"); for (i = 0; i < m; i++) { for (j = 0; j < 4; j++) { a[i][j]=sc.next(); } System.out.println(); } for (i = 0; i < m; i++) { for (j = 0; j < 2; j++) { k=0; int temp=0; int index=0; while(((i-k)>=0)&&(i>0)) { if(a[i][j].equals(s[i-k])) { temp=1; index=i-k; } k++; } if(temp==1) { mt[index]+=1; gf[index]+=Integer.parseInt(a[i][(j+2)]); ga[index]+=Integer.parseInt(a[i][(3-j)]); if((Integer.parseInt(a[i][j+2]))>(Integer.parseInt(a[i][3-j]))) { pt[index]+=2; } else if(Integer.parseInt(a[i][j+2])==Integer.parseInt(a[i][3-j])) { pt[index]+=1; } else { pt[index]+=0; } } else { s[x]=a[i][j]; mt[x]+=1; gf[x]=Integer.parseInt(a[i][(j+2)]); ga[x]=Integer.parseInt(a[i][(3-j)]); if((Integer.parseInt(a[i][j+2]))>(Integer.parseInt(a[i][3-j]))) pt[x]=2; else if(Integer.parseInt(a[i][j+2])==Integer.parseInt(a[i][3-j])) pt[x]=1; else pt[x]=0; x++; } } } int v=m; int[] p = new int[n]; int b; int[] r = new int[n]; for (i = 0; i < m; i++) { for (j = 0; j < (m-i-1); ++j) { if(p[j]<p[j+1]) { b=p[j]; p[j]=p[j+1]; p[j+1]=b; } } int[] mp = new int[n]; int[] goalf = new int[n]; int[] goala = new int[n]; String tn[] = new String[n+n]; int[] g = null; for (i = 0; i < m; i++) { for (j = 0; j < m; j++) { if(pt[i]==p[j]) { tn[j]=s[j]; mp[j]=mt[i]; goalf[j]=gf[i]; goala[j]=ga[i]; goala[j]=ga[i]; g[j]=gd[i]; } } } for (i = m; i < n; i++) { mp[i]=0; goalf[i]=0; goala[i]=0; g[i]=0; p[i]=0; } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if((z[i].equals(tn[j]))) { z[i]="0"; } } } for (i = 0; i < n; i++) { if(z[i]!="0") { tn[v]=z[i]; v++; } } for (i = 0; i < n; i++) { if(p[i]==p[i+1]) { if(g[i]>g[i+1]) { r[i]=i+1; i=i+1; } else if(g[i]<g[i+1]) { r[i+1]=i+1; r[i]=i+2; i=i+1; } else { try { int d = tn[i].compareToIgnoreCase(tn[i+1]); if(d>0) { s[i]=tn[i]; tn[i]=tn[i+1]; tn[i+1]=s[i]; } } catch (Exception e) { e.printStackTrace(); } r[i]=i+1; r[i+1]=i+1; i=i+1; } } else r[i]=i+1; } System.out.println("\n\n\n\n"); System.out.println("\t\t\t"+"Football Points Table"+"\t\t"); System.out.println("\n\n"); System.out.println("Name"+"\t\t"+"Match"+"\t"+"GoalF"+"\t"+"GoalA"+"\t"+"GD"+"\t"+"Points"+"\t"+"Rank"); for (i = 0;i < n; i++) { System.out.println(tn[i]+"\t\t"+mp[i]+"\t"+goalf[i]+"\t"+goala[i]+"\t"+g[i]+"\t"+p[i]+"\t"+r[i]); } } } }
Python program for Sorting Boxes Problem
Java program for Forest Fire Problem
In a Conference ,attendees are invited for a dinner after the conference.The Co-ordinator,Sagar arranged around round tables for dinner and want to have an impactful seating experience for the attendees.Before finalizing the seating arrangement,he wants to analyze all the possible arrangements.These are R round tables and N attendees.In case where N is an exact multiple of R,the number of attendees must be exactly N//R,,If N is not an exact multiple of R, then the distribution of attendees must be as equal as possible.Please refer to the example section before for better understanding.
For example, R = 2 and N = 3
All possible seating arrangements are
(1,2) & (3)
(1,3) & (2)
(2,3) & (1)
Attendees are numbered from 1 to N.
Input Format:
- The first line contains T denoting the number of test cases.
- Each test case contains two space separated integers R and N, Where R denotes the number of round tables and N denotes the number of attendees.
Output Format:
Single Integer S denoting the number of possible unique arrangements.
Constraints:
- 0 <= R <= 10(Integer)
- 0 < N <= 20 (Integer)
2 5
10
R = 2, N = 5
(1,2,3) & (4,5)
(1,2,4) & (3,5)
(1,2,5) & (3,4)
(1,3,4) & (2,5)
(1,3,5) & (2,4)
(1,4,5) & (2,3)
(2,3,4) & (1,5)
(2,3,5) & (1,4)
(2,4,5) & (1,3)
(3,4,5) & (1,2)
Arrangements like
(1,2,3) & (4,5)
(2,1,3) & (4,5)
(2,3,1) & (4,5) etc.
But as it is a round table,all the above arrangements are same.
public class SeatingArrangement
//To find the factorial of the given number
public static int fact(int n)
{
int y = 1;
if(n==0||n==1)
return y;
else if(n>1)
{
for(int a = n;a>1;a–)
y = y*a;
return y;
}
else
return -1;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Number of test case
int t = sc.nextInt();
for(int b = 1;b0&&d=0&&r<=20)
{
int out = 1;
//The combination formula (nCr = n!/r!*(n-r)!)
out = fact(d)/(fact(r)*fact(d-r));
System.out.println(out);
}
}
}
}
JOB ALERT ON INSTAGRAM | FOLLOW NOW>> |
JOB ALERT ON YOUR EMAIL DAILY | SUBSCRIBE NOW>> |
Keep an eye on Dailyrecruitment.in for the most up-to-date information about upcoming exams and results. Find out about official notices, Exam Patterns, Syllabus, Previous Question Papers, Expected Cut Off, Results, Merit List, Study Materials, and much more. Now is the time to bookmark in order to take advantage of even more amazing career opportunities.
Govt Jobs by Qualifications
Education & Vacancies | Salary | Apply Link |
---|---|---|
12th Pass Govt Jobs - 18,000+ Vacancies | Rs. 5,200 - 92,300 | Apply Now |
ITI Pass Jobs - 3,500 Vacancies | Rs. 5,200 - 35,000 | Apply Now |
Any Graduate Jobs - 19,100 Vacancies | Rs. 5,200 - 92,300 | Apply Now |
Central Govt Jobs | Rs. 5,200 - 17,000 | Apply Now |
Bank Jobs - 1,000 Vacancies | Rs. 5,200 - 29,200 | Apply Now |
Diploma Jobs - 9,300 Vacancies | Rs. 5,200 - 35,000 | Apply Now |
BTech/BE Jobs - 18,000 Vacancies | Rs. 15,000 - 1,00,000 | Apply Now |
Data Entry Jobs - 1,300 Vacancies | Rs. 5,200 - 29,200 | Apply Now |
Private Jobs | Rs. 10,000 - 67,700 | Apply Now |