Cognizant GenC Elevate Sample Coding Question 7
In this article, we will discuss about Coding Question with their solution in java and python. This is a simple mathematics based question in which you have to find the permutation of a given object.
Williamson is an analyst he needs to analyse a particular topic for performing analysis for that he needs to find a permutation of a given object.He don’t know how to find permutation so for simplifying his work he is hiring one software developer who can code for him and find a permutation and combination of a given object.
Consider you are giving an interview to williamson for working with him. Find a permutation of given input to proof that you are fit for his requirement.
nCr where n and r are numbers given by Williamson to you
nCr is defined as n! / (r! x (n-r)!)
Here, n! denotes the factorial of a number. Also, you have to calculate this number as modulo
- input1: The number n.
- Input2: The number r.
- Input3: The number m,
- The value of nCr%m.
n=3.r=2,m=100 So, n!=3!=6, r!=2!=2, (n-1)!= 1!=1.
So, nCr = (6/(2*1))%1000000009= 3.
n=5,r=2, m=100 So, n!=5!=120, r!=2=2, (n-1)!= 3!=6.
So, nCr = (120/(2*6))%1000000009= 10.
public class Main
static int fact (int number)
int f = 1;
int j = 1;
while (j <= number)
f = f * j;
public static void main (String args)
Scanner sc = new Scanner (System.in);
int n = sc.nextInt ();
int r = sc.nextInt ();
long m = sc.nextLong ();
int result = fact (n) / (fact (r) * fact (n - r));
long finalresult = (long) result % m;
System.out.println ("" + result);