TCS Coding Questions 2022 Day 3 Slot 2
Coding Question 1 for 2022 (September slot)
In this article, we will discuss about the TCS Coding Question which is asked in the TCS placement test. This type of Coding Questions will help you to crack your upcoming TCS exam as well as during your interview process.
TCS Coding Question Day 3 Slot 2 – Question 2
An international round table conference will be held in india. Presidents from all over the world representing their respective countries will be attending the conference. The task is to find the possible number of ways(P) to make the N members sit around the circular table such that.
The president and prime minister of India will always sit next to each other.
Example 1:
Input :
4 -> Value of N(No. of members)
Output :
12 -> Possible ways of seating the members
Explanation:
2 members should always be next to each other.
So, 2 members can be in 2!ways
Rest of the members can be arranged in (4-1)! ways.(1 is subtracted because the previously selected two members will be considered as single members now).
So total possible ways 4 members can be seated around the circular table 2*6= 12.
Hence, output is 12.
Example 2:
Input:
10 -> Value of N(No. of members)
Output :
725760 -> Possible ways of seating the members
Explanation:
2 members should always be next to each other.
So, 2 members can be in 2! ways
Rest of the members can be arranged in (10-1)! Ways. (1 is subtracted because the previously selected two members will be considered as a single member now).
So, total possible ways 10 members can be seated around a round table is
2*362880 = 725760 ways.
Hence, output is 725760.
The input format for testing
The candidate has to write the code to accept one input
First input – Accept value of number of N(Positive integer number)
The output format for testing
The output should be a positive integer number or print the message(if any) given in the problem statement(Check the output in example 1, example2)
Constraints :
2<=N<=50
#include<stdio.h>
int main() {
int n;
scanf("%d", &n);
int fact[n + 1];
fact[0] = 1;
for (int i = 1; i <= n; i++) {
fact[i] = fact[i - 1] * i;
}
printf("%d\n", fact[n - 1] * 2);
return 0;
}
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector fact(n + 1, 1);
for (int i = 1; i <= n; i++) {
fact[i] = fact[i - 1] * i;
}
cout << fact[n - 1] * 2 << endl;
return 0;
}
import java.math.BigInteger;
import java.util.*;
class Main
{
public static BigInteger fact(int number)
{
BigInteger res= BigInteger.ONE;
for (int i = number; i > 0; i--)
res = res.multiply(BigInteger.valueOf(i));
return res;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
BigInteger res=fact(n-1);
System.out.println(res.multiply(BigInteger.valueOf(2)));
}
}
}
n = int(input())
fact = [0] * (n + 1)
fact[0] = 1
for i in range(1, n + 1):
fact[i] = fact[i - 1] * i
print(fact[n - 1] * 2)

Login/Signup to comment