Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
(Mathematical Based)
1) Lucky Numbers
Lucky numbers are subset of integers. Rather than going into much theory, let us see the process of arriving
at lucky numbers,
Take the set of integers
1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,……
First, delete every second number, we get following reduced set.
1,3,5,7,9,11,13,15,17,19,…………
Now, delete every third number, we get
1, 3, 7, 9, 13, 15, 19,….….
Continue this process indefinitely……
Any number that does NOT get deleted due to above process is called “lucky”.
Therefore, set of lucky numbers is 1, 3, 7, 13………
Now, given an integer ‘n’, write a function to say whether this number is lucky or not.
Examples:
Input: n = 8
Output: true
8 can be expressed as 23
Input: n = 49
Output: true
49 can be expressed as 72
Input: n = 48
Output: false
48 can't be expressed as xy
Input: x = 4
Output: 2
Input: x = 11
Output: 3
..................
9) Check whether a given point lies inside a triangle
or not
Given three corner points of a triangle, and one more point P. Write a function to check whether P lies within
the triangle or not.
For example, consider the following program, the function should return true for P(10, 15) and false for
P'(30, 15)
B(10,30)
/ \
/ \
/ \
/ P \ P'
/ \
Output
Monday
12) Measure one liter using two vessels and infinite
water supply
There are two vessels of capacities ‘a’ and ‘b’ respectively. We have infinite water supply. Give an efficient
algorithm to make exactly 1 litre of water in one of the vessels. You can throw all the water from any vessel
any point of time. Assume that ‘a’ and ‘b’ are Coprimes.
Output
No
p = {5, 5};
output
Yes
The first few Catalan numbers for n = 0, 1, 2, 3, … are 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, …
Input: n = 20
Output: 4
Factorial of 20 is 2432902008176640000 which has
4 trailing zeroes.
Input: n = 100
Output: 24
Input: n = 36
Output: p = 49
Input: n = 100
Output: p = 455
// Note that 4*5*5 = 100 and 455 is the smallest such number
Input: n = 1
Output:p = 11
Input: n = 13
Output: 75 degree
Output: 3
Output: 3
B[] = {1, 2, 4}
Output: 3
Output: 3
Input: n = "218765"
Output: "251678"
Input: n = "1234"
Output: "1243"
Input: n = "4321"
Input: n = "534976"
Output: "536479"
Input: n = 5
Output: 0 1 4 9 16
Input: n = 6
Output: 0 1 4 9 16 25
Input n = 3
Output: 3
Explanation:
Input n = 4
Output: 5
Explanation:
For a 2 x 4 board, there are 5 ways
1) All 4 vertical
2) All 4 horizontal
30) Given p and n, find the largest x such that p^x divides n!
Given an integer n and a prime number p, find the largest x such that p x (p raised to power x) divides n!
(factorial)
Examples:
Input: 0 1
Input: 12 122
Input: 2 720
Input: n = 5
Input: n = 12
Input: n = 328
Input: n = 5
Output: 6
The pairs are (0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (0, 2)
Input: n = 6
Output: 8
The pairs are (0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (0, 2),
Input: n = 1
Output: 1
Input: n = 2
Output: 2
Input: n = 4
Output: 5
"forgeeksgeeks", "zuiqkeegs"};
Output:
# $ % & @ ^
# $ % & @ ^
Input: appointments [] = { {1, 5} {3, 7}, {2, 6}, {10, 15}, {5, 6}, {4, 100}}
Output: 393
Output: 29
Output: 0
Output: 1461
Example:
Input:
arr[] = {1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1}
Output:
Index 9
Input:
arr[] = {1, 1, 1, 1, 0}
Output:
Index 4
44) How to check if two given sets are disjoint?
Given two sets represented by two arrays, how to check if the given two sets are disjoint or not? It may be
assumed that the given arrays have no duplicates.
set2[] = {2, 1, 3, 5}
set2[] = {7, 2, 1, 5}
Examples:
Output: 3
There are at-most three trains at a time (time between 11:00 to 11:20)
Output: 1
Output: 2
Input: 6
Output: 5
Possible valid expressions are ((())), ()(()), ()()(), (())() and (()())
51) Write a C program to find determinant / Inverse/ Transpose and Disjoint of a nxn
matrix.
o/p – one thousand seven hundred ninety five rupees and fifty paisa only.
Input: N = 2
Output: 3
Input: N = 3
Output: 5
Example 1:
Input: arr[] = {1, 3, 0, 2};
Output: arr[] = {2, 0, 3, 1};
Explanation for the above output.
Since arr[0] is 1, arr[1] is changed to 0
Since arr[1] is 3, arr[3] is changed to 1
Since arr[2] is 0, arr[0] is changed to 2
Since arr[3] is 2, arr[2] is changed to 3
Output: 2
Output: 5
Output: 10