Genc Next
Genc Next
of an integer N.
Function Description
Constraints
1 < N < 30
1 < P < 10
A Derangement is a permutation of n elements, such that no element
appears in its original position.
For example, a derangement of {0, 1, 2, 3} is {2, 3, 1, 0}.
Given a number n, find the total number of Derangements of a set of n
elements.
Input Specification:
input1: N, the number of Objects
Output Specification:
Return the number of arrangements in which no object occurs at its
original
position
Example 1:
Input: n = 2
Output: 1
For two elements say {0, 1}, there is only one possible derangement {1,
0}
Example 2:
Input: n = 3
Output: 2
For three elements say {0, 1, 2}, there are two possible derangements
{2, 0, 1} and {1, 2, 0}
Example 3:
Input: n = 4
Output: 9
For four elements say {0, 1, 2, 3}, there are 9 possible derangements {1,
0, 3, 2} {1, 2, 3, 0} {1, 3, 0, 2}, {2, 3, 0, 1}, {2, 0, 3, 1}, {2, 3,1, 0}, {3,
0, 1, 2}, {3, 2, 0, 1} and {3, 2, 1, 0
where and
d(n) = (n-1) * (d(n-1) + d(n-2))
d(0) = 1, d(1) = 0
Jasleen has bought a new bulb factory. The factory has a single file of
machines, numbered from 1 to N. Each machine has a certain number of
fully prepared bulbs.
Jasleen has a rule she wants to follow. She wants to collect an equal
amount of bulb from
each machine from which she collects bulbs.
Jasleen can start collecting bulb from any machine, but once she starts
collecting, she collects from every consecutive machine until she reaches
the last machine she wants to collect from. Find the maximum number of
bulbs she can collect.
Input Specification:
Input1: N, the number of machines
Input2: An array of N elements (a1,a2 a3……aN], denoting the number of
fully prepared bulbs in each machine of the factory.
Output Specification:
An integer output denoting the maximum number of bulbs that Allie can
collect.
Example 1:
input1: 3
Input2: [1,2,3]
Output: 3
Example 2:
input1: 4
Input2: [5,8,9,10]
Output:20
Input1: 5
Input2: 8 5 9 7 10
Output: 25
.
Henry is extremely keen on history and every one of the ages of his
family. He does a ton of exploration and understands that he has
plummeted from the incomparable Amaya line. After a ton of looking
through old records and the most recent records of the general public, he
can discover all the parent-kid connections in his family right from the
extraordinary ruler Ming of the tradition to himself.
These connections are given in the structure of a direct exhibit where the
emperor is at the main position and his kids are at pos (2i + 1) and (2i +
2)
This is the pattern followed throughout.
Henry needs to sort out every one of the kin of individual X from the
information.
Write a program for Henry to figure out all the siblings of person X from
the data.
Return the sorted list of all of Henry’s siblings.
If no sibling return {-1}
input 1: N, the length of the array
input2: An array representing the ancestral tree
input 3: X, the person whose siblings are sought.
output – return the array of all siblings in increasingly sorted order.
Example 1 :
input 1: 5
input 2: {1,2,3,4,5}
input 3: 1
output: {-1}
Explanation: x is the root of the tree and has no siblings
Example 2 :
input 1: 6
input 2: {1,2,3,4,5,6}
input 3: 5
output: {4,6}
Explanation: {2,3 } are the children of {1}. {4,5,6 } are the children of
{2,3}, thus the siblings of x= 5 are {4,6}
Given a number n, the task is to find the remainder when n is divided by
11. The input number may be very large.Since the given number can be
very large, you can not use n % 11.
Input Specification:
inputs a large number in the form of a string
Output Specification:
Example1:
Example2:
Example3:
Write a program that adds up the largest row sum and the largest column
sum from an N- rows*M-columns array of numbers to help devilliers for
finding his lucky number for the final match jersey.
Input Specification:
Input 1: Integer for row dimension of the array
Input 2: Integer for column dimension of the array
Input 3: Array elements to be entered in row major.
Output Specifications:
Largest row sum+ Largest column sum
Example 1:
Input1:4
Input2: 4
Input3: {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4}
Output: 26
Explanation:
The array has 4 rows (input1) and 4 columns (input2). The largest sum
among the four columns is 10 and the largest sum among the four rows is
16. We get the final sum of 26 (10+16).
Example 2:
Input1:2
Input2: 2
Input3: {1,2,5,6}
Output: 19
Explanation:
The array has 2 rows (input1) and 2 columns (input2). The elements in the
first row are 1 and 2 and the elements in the second row are 5 and 6
(input3). The largest sum among the two columns is 8(2+6) By adding
those two up. We get the final sum of 19 (11+8).
Example 3:
Input1: 3
Input2: 3
Input3: {3,6,9,1,4,7,2,8,9}
You want to buy a particular stock at its lowest price and sell it later at its
highest price. Since the stock market is unpredictable, you steal the price
plans of a company for this stock for the next N days.
Find the best price you can get to buy this stock to achieve maximum
profit.
Input Specification:
Output Specification:
Your function must return the best price to buy the stock at.
Example1:
Input1: 5
Input2: (-39957,-17136,35466,21820,-26711}
Output: -57093
Explanation: The best time to buy the stock will be on Day 2 when the
price of the stock will be -57093.
Example2:
Input1: 5
Input2: (-39957, -17136, 1, 2, -26711)
Output: -80801
Explanation: The best time to buy the stock will be on Day 5 when the
price of the stock will be -83801.
Example3:
Input1: 9
Input2: (-4527,-1579,-38732,-43669,-9287,-48068,-30293,-30867,18677}
Output: -207022
Explanation: The best time to buy the stock will be on Day 8 when the
price of the stock will be -207022.