TCS Digital Coding Questions and Answers 2025 | TCS Digital Advanced Coding Questions and Answers | Previously Asked TCS Digital Coding Questions | TCS Digital Coding Solved Old Questions | TCS Digital Coding Questions For Freshers
TCS Digital Coding Questions and Answers 2025: Here we have provided the study material for the coding test. TCS will conduct the Coding Test for each hiring Process. Every year, they hire many employees to fill many positions. As of now, they are going to hold the test for the TCS Digital Coding. So, aspirants who are going to attend this hiring process kindly check out the TCS Digital Coding Questions & Answers before attending the process. Aspirants who pass in the Online Test will qualify for the coding test process. The coding test will be conducted for the process to check the candidate’s capability.
The Tech Mahindra coding questions will be asked in any language. In the below section, we have provided the Java, C, C++, and Python Coding Questions with Solutions. With the clear Explanation, we have provided all the details here. Solve the Frequently Asked coding test Questions to help with your study. Before entering the coding test, aspirants can start their preparation by downloading or viewing the practice questions. More details like Cut Off, Salary, Hike, Increment, Annual Appraisal, etc. are available on this page
TCS Digital Coding Questions Marking Scheme
Coding Marks
|
Marks
|
---|---|
0 Test Case
|
0 Marks
|
1 Test Case
|
5 Marks
|
2 Test Case
|
8 Marks
|
3 Test Case
|
12 Marks
|
4 Test Case
|
18 Marks
|
5 Test Case
|
22 Marks
|
TCS Digital Coding Test Pattern 2025 (Updated)
You may use any of the following languages during the test:
- C
- C#
- C++
- Java 7
- Kotlin
- Lua
- Perl
- Python
- Python3
- Ruby
- Scala
- Erlang
- go
- Haskel
- Java
import java.util.*; public class Main { static int find(int n1, int n2) { int count = 0; for (int i = n1 ; i <= n2 ; i++) { int num = i; boolean[] visited = new boolean[10]; while (num > 0) { if (visited[num % 10] == true) break; visited[num % 10] = true; num /= 10; } if (num == 0) count++; } return count; } public static void main(String[] args) { int n1 = 101, n2 = 200; System.out.println(find(n1, n2)); } }
TCS Digital Advanced Coding Questions and Answers
Q) Roco is an island near Africa which is very prone to forest fire. Forest fire is such that it destroys the complete forest. Not a single tree is left.This island has been cursed by God , and the curse is that whenever a tree catches fire, it passes the fire to all its adjacent tree in all 8 directions,North, South, East, West, North-East, North-West, South-East, and South-West.And it is given that the fire is spreading every minute in the given manner, i.e every tree is passing fire to its adjacent tree.Suppose that the forest layout is as follows where T denotes tree and W denotes water.
Your task is that given the location of the first tree that catches fire, determine how long would it take for the entire forest to be on fire. You may assume that the lay out of the forest is such that the whole forest will catch fire for sure and that there will be at least one tree in the forest
Input Format:
- First line contains two integers, M, N, space separated, giving the size of the forest in terms of the number of rows and columns respectively.
- The next line contains two integers X,Y, space separated, giving the coordinates of the first tree that catches the fire.
- The next M lines, where ith line containing N characters each of which is either T or W, giving the position of the Tree and Water in the ith row of the forest.
Output Format:
Single integer indicating the number of minutes taken for the entire forest to catch fire
Constrains:
- 3 ≤ M ≤ 20
- 3 ≤ N ≤ 20
Sample Input 1:
3 3
W T T
T W W
W T T
Sample Output 1:
5
Explanation:
In the second minute,tree at (1,2) catches fire,in the third minute,the tree at (2,1) catches fire,fourth minute tree at (3,2) catches fire and in the fifth minute the last tree at (3,3) catches fire.
Sample Input 2:
6 6
1 6
W T T T T T
T W W W W W
W T T T T T
W W W W W T
T T T T T T
T W W W W W
Sample Output 2:
16
EXAMPLE
C++ PROGRAM
#include <bits/stdc++.h> using namespace std; char f[21][21]; int n,m; struct node{int a,b;}; bool valid(int x,int y) {return (x>=0&&y>=0&&x<n&&y<m);} bool step(node temp){return (temp.a==-1&&temp.b==-1);} int main() { cin>>n>>m; int x,y,i,j,count=0;int ans=1; cin>>x>>y;x--;y--; for(i=0;i<n;i++) for(j=0;j<m;j++) cin>>f[i][j]; f[x][y]='X'; queueq; node temp; temp.a=x;temp.b=y; q.push(temp); temp.a=-1;temp.b=-1; q.push(temp); while(!q.empty()) { bool flag=false; while(!step(q.front())) { node count=q.front(); if(valid(count.a+1,count.b)&&f[count.a+1][count.b]=='T')//a+1,b { if(flag==false){flag=true;ans++;} f[count.a+1][count.b]='X'; count.a++; q.push(count); count.a--; } if(valid(count.a+1,count.b+1)&&f[count.a+1][count.b+1]=='T')//a+1,b+1 { if(flag==false){flag=true;ans++;} f[count.a+1][count.b+1]='X'; count.a++;count.b++; q.push(count); count.a--;count.b--; } if(valid(count.a+1,count.b-1)&&f[count.a+1][count.b-1]=='T')//a+1,b-1 { if(flag==false){flag=true;ans++;} f[count.a+1][count.b-1]='X'; count.a++;count.b--; q.push(count); count.a--;count.b++; } if(valid(count.a,count.b+1)&&f[count.a][count.b+1]=='T')//a,b+1 { if(flag==false){flag=true;ans++;} f[count.a][count.b+1]='X'; count.b++; q.push(count); count.b--; } if(valid(count.a,count.b-1)&&f[count.a][count.b-1]=='T')//a,b-1 { if(flag==false){flag=true;ans++;} f[count.a][count.b-1]='X'; count.b--; q.push(count); count.b++; } if(valid(count.a-1,count.b-1)&&f[count.a-1][count.b-1]=='T')//a-1,b-1 { if(flag==false){flag=true;ans++;} f[count.a-1][count.b-1]='X'; count.a--;count.b--; q.push(count); count.a++;count.b++; } if(valid(count.a-1,count.b+1)&&f[count.a-1][count.b+1]=='T')//a-1,b+1 { if(flag==false){flag=true;ans++;} f[count.a-1][count.b+1]='X'; count.a--;count.b++; q.push(count); count.a++;count.b--; } if(valid(count.a-1,count.b)&&f[count.a-1][count.b]=='T')//a-1,b { if(flag==false){flag=true;ans++;} f[count.a-1][count.b]='X'; count.a--; q.push(count); count.a++; } q.pop(); } q.pop(); if(!q.empty()) { temp.a=-1; temp.b=-1; q.push(temp); } /* cout<<endl; for(i=0;i<n;i++) {for(j=0;j<m;j++) {cout<<f[i][j]<<" ";}cout<<endl;} cout<<endl<<endl; */ } cout<<ans; }
JAVA PROGRAM
import java.util.HashMap; import java.util.Scanner; class Temp { static void print(int [][] arr){ for(int i=0;i<arr.length;i++){ for (int j=0;j<arr[0].length;j++){ System.out.print(arr[i][j]+"\t"); } System.out.println(); } } public static void main (String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int [][] array = new int[N][N]; HashMap<Integer, Integer> map = new HashMap<>(); int powerpoints = 1 + (N*N)/11; int counter = 1; int row = 0, col = 0; // for the current row/col that we are end int endRow = 0, endColumn = 0; // for the row/col where we need to stop map.put(0,0); for(int i=0;i<N/2;i++){ row = col = i; endColumn = N-i-1; while (col < endColumn) { array[row][col] = counter; if (counter % 11==0) map.put(row,col); counter++; col++; } endRow = N-i-1; while (row<endRow){ array[row][col] = counter; if (counter % 11==0) map.put(row,col); counter++; row++; } endColumn = i; while (col>endColumn){ array[row][col] = counter; if (counter % 11==0) map.put(row,col); counter++; col--; } endRow = i; while (row>endRow){ array[row][col] = counter; if (counter % 11==0) map.put(row,col); counter++; row--; } } if (N%2==1) array[N/2][N/2] = N*N; print(array); System.out.println("Total Power Points: " + powerpoints); for (Integer key: map.keySet()) { System.out.println("("+key+ ","+map.get(key)+")"); } } }
Problem Statement:- 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.
EXAMPLE
C++ PROGRAM
#include<bits/stdc++.h> using namespace std; typedef long long int ll; map <ll,ll> dp; int fac(int n) { if(dp[n]) return dp[n]; dp[n]=n*fac(n-1); return dp[n]; } int func(int n) { if(n<=3) return 1; return fac(n-1); } int main() { dp[0]=dp[1]=1; int tests;cin>>tests; while(tests--) {int R,N,c=1; cin>>R>>N; if(N<=R) { cout<<1; continue; } int a=N/R,n=N%R; ll ans=fac(N)/(pow(fac(a),R-n) * pow(fac(a+1),n) )/fac(n)/fac(R-n); for(int i=1;i<=n;i++) c*=func(a); for(int i=n+1;i<=R;i++) c*=func(a-1); cout<<c*ans;} }
JAVA PROGRAM
import java.util.*; public class Stack { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testcases = scanner.nextInt(); int tables = 0,people; while (testcases-->0) tables = scanner.nextInt(); people = scanner.nextInt(); System.out.println(find(tables,people)); } public static int find(int r,int n) { int x = n/r; int y1 = n%r; int x1 = 0; int ans1 = 1; while(r!=0) { if(y1>0) { x1 = x+1; y1 = y1-1; } else { x1 = x; } ans1 = ans1*combination(n,x1); n = n-x1; r--; } return ans1; } public static int factorial(int n) { if(n==0||n==1) { return 1; } return n * factorial(n-1); } public static int combination(int n,int r) { return factorial(n)/(factorial(n-r)*factorial(r)); } }
PYTHON PROGRAM
testcases = int(input()) for i in range(testcases): tables, people = map(int, input().split()) result = 1 if tables >= people: print(result) else: PA = people // tables PB = PA + 1 TB = people % tables TA = tables - TB # Using DP to store factorials pre-hand fact = [1] for j in range(1, people + 1): fact.append(j*fact[j-1]) for i in range(TB): result = result * (fact[people]//(fact[PB]*fact[people-PB])) people = people - PB for i in range(TA): result = result * (fact[people]//(fact[PA]*fact[people-PA])) people = people - PA print(result)
JOB ALERT ON INSTAGRAM | FOLLOW NOW>> |
JOB ALERT ON YOUR EMAIL DAILY | SUBSCRIBE NOW>> |
Follow regularly our Dailyrecruitment.in site to get upcoming all up-to-date information.
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 |