IT&CircuitStream Sessionplan 22.05.19
IT&CircuitStream Sessionplan 22.05.19
Session 2
Problem1: Output:
Given a number n, we can divide it in only three 13
parts n/2, n/3 and n/4 (we will consider only integer 27
part). The task is to find the maximum sum we can Explanation:
make by dividing number in three parts recursively Testcase1:
and summing up them together. Input : n = 12
Note: Sometimes, the maximum sum can be Output : 13
obtained by not dividing n. We break n = 12 in three parts {12/2, 12/3, 12/4} =
Input: {6, 4, 3}, now current sum is = (6 + 4 + 3) = 13
The first line of input contains an integer T denoting Again, we break 6 = {6/2, 6/3, 6/4} = {3, 2, 1} = 3 +
the number of test cases. Then T test cases follow. 2 + 1 = 6 and further breaking 3, 2 and 1 we get
The first line of each test case contains the integer n. maximum summation as 1, so breaking 6 in three
Output: parts produces maximum sum 6 only similarly
For each testcase, in a new line, print the maximum breaking 4 in three parts we can get maximum
sum possible. sum 4 and same for 3 also. Thus maximum sum by
Constraints: breaking number in parts is=13
1<= T <=100 Testcase2:
1<= n <=105 Input : n = 24
Example: Output : 27
Input: We break n = 24 in three parts {24/2, 24/3, 24/4} =
2 {12, 8, 6}, now current sum is = (12 + 8 + 6) = 16.
12 As seen in example, recursively breaking 12 would
24 produce value 13. So our maximum sum is 13 + 8 +
6 = 27.
Problem2: Constraints:
Given an array A[] of integers find sum of product of 1<=T<=100
all pairs of array elements. 1<=N<=100
Input: Example:
First line consists of T test cases. First line of every Input:
test case consists of N, denoting number of elements 1
of array. Second line consists of elements of array. 3
Output: 134
Single line output, print the sum of products. Output: 19
Problem3: Example:
Given an array of digits (values are from 0 to 9), find Input
the minimum possible sum of two numbers formed 2
from digits of the array. All digits of given array 6
must be used to form the two numbers. 684523
Input: 5
The first line of input contains an integer T denoting 5 3 0 7 4
the number of test cases. Then T test cases follow. Output:
First line of each test case contains an integer N 604
denoting the size of the array. Next line of each test 82
contains N space seperated integers denoting the Explanation:
elements of the array. Test Case 1-
Output: The minimum sum is formed by numbers
For each test case output a single line containing 358 and 246
the required sum. Test Case 2 -
Constraints: The minimum sum is formed by numbers
1<=T<=100 35 and 047
1<=N<=50
Session 3
Problem1: Constraints:
Given an array of size N consisting of only 0's and 1 <= T <= 100
1's ,which is sorted in such a manner that all the 1's 1 <= N <= 30
are placed first and then they are followed by all the 0 <= A[i] <= 1
0's. You have to find the count of all the 0's. Example :
Input: Input:
The first line of input contains an integer T denoting 3
the number of test cases. Then T test cases follow. 12
The first line of each test case contains an integer N, 1 1 1 1 1 1 1 1 1 0 0 0
where N is the size of the array A[ ]. 5
The second line of each test case contains N space 0 0 0 0 0
separated integers of all 1's follwed by all the 0's, 6
denoting elements of the array A[ ]. 111111
Output: Output:
Print out the number of 0's in the array. 3
5
0
Problem2: Constraints:
Consider a game where a player can score 3 or 5 or 1 ≤ T ≤ 100
10 points in a move. Given a total score n, find 1 ≤ n ≤ 1000
number of distinct combinations to reach the given Example:
score. Input
Input: 3
The first line of input contains an integer T denoting 8
the number of test cases. T testcases follow. Thefirst 20
line of each test case is n. 13
Output: Output
For each testcase, in a new line, print number of 1
ways/combinations to reach the given score. 4
2
Problem3: Constraints:
Given an unsigned integer N. The task is to swap all 1 ≤ T ≤ 100
odd bits with even bits. For example, if the given 1 ≤ N ≤ 100
number is 23 (00010111), it should be converted to Example:
43(00101011). Here, every even position bit is Input:
swapped with adjacent bit on right side(even 2
position bits are highlighted in binary 23
representation of 23), and every odd position bit is 2
swapped with adjacent on left side. Output:
Input: 43
The first line of input contains T, denoting the 1
number of testcases. Each testcase contains single Explanation:
line. Testcase 1: BInary representation of the given
Output: number; 00010111 after swapping 00101011.
For each testcase in new line, print the converted
number.
Session 4
Problem1: Constraints:
In Game of Nim, two players take turns removing 1 <= T <= 100
objects from heaps or the pile of stones. 1 <= N <= 1000
Suppose two players A and B are playing the game. Example:
Each is allowed to take only one stone from the pile. Input:
The player who picks the last stone of the pile will 2
win the game. Given N the number of stones in the 3
pile, the task is to find the winner, if player A starts 15
the game . Output:
Input: Player A
The input line contains T, denoting the number of Player A
test cases. Then T test case follows, a single line of Explanation:
the input containing a positive integer N. Testcase 1: Player A remove stone 1 which is at the
Output: top, then Player B remove stone 2
Print the winner i.e. Player A or Player B for each and finally player A removes the last stone.
testcase in a separate line.
Problem2: Example:
Given a string s, find the minimum number of Input
changes required to it so that all substrings of the 3
string become distinct. Note: length of string is aab
atmost 26. aebaecedabbee
Input: ab
The first line contains an integer T, number of test Output 1
cases. For each testcase there is only one line 8
containing s atmost 26 characters. 0
Output: Explanation
For each testcase in new line, print the minimum Testcase 1: If we change one instance of 'a' to any
number of changes to the string. character from 'c' to 'z', we get all distinct
Constraints: substrings.
1 <= T <= 100 Testcase 2: We need to change 2 a's, 2 b's and 4 e's
1 <= |s| <= 26 to get distinct substrings.
Testcase 3: As no change is required hence 0.
Problem3: Constraints:
Given an M X N matrix with your initial position at 1 ≤ T ≤ 30
top-left cell, find the number of possible unique 1 ≤ M ≤ 15
paths to reach the bottom right cell of the matrix 1 ≤ N ≤ 15
from the initial position. Example:
Note: Possible moves can be either down or right at Input:
any point in time, i.e., we can move to matrix[i+1][j] 2
or matrix[i][j+1] from matrix[i][j]. 22
Input: 34
The first line contains an integer T, depicting total Output:
number of test cases. Then following T lines 2
contains an two integers A and B depicting the size 10
of the grid.
Session 5
Problem1: Output:
Given a string s and a dictionary of words dict, add For each test case, print all possible strings in one
spaces in s to construct a sentence where each line. Each string is enclosed in (). See Example.
word is a valid dictionary word. Return all such If no string possible print "Empty" (without quotes).
possible sentences. Constraints:
For example, given 1<=T<=100
s = "snakesandladder", 1<=N<=20
dict = ["snake", "snakes", "and", "sand", "ladder"]. 1<=Length of each word in dictionary <=15
A solution is ["snakes and ladder", "snake sand 1<=Length of s<=1000
ladder"]. Note: Make sure the strings are sorted in your
Input: result.
The first line contains an integer T, denoting the Example:
number of test cases. Input:
Every test case has 3 lines. 1
The first line contains an integer N, number of 5
words in the dictionary. lr m lrm hcdar wk
The second line contains N strings denoting the hcdarlrm
words of the dictionary. Output:
The third line contains a string s. (hcdar lr m)(hcdar lrm)
Problem2: profit.
Given a set of N jobs where each job i has a Constraints:
deadline and profit associated to it. Each job takes 1 1 <= T <= 100
unit of time to complete and only one job can be 1 <= N <= 100
scheduled at a time. We earn the profit if and only 1 <= Deadline <= 100
if the job is completed by its deadline. The task is to 1 <= Profit <= 500
find the maximum profit and the number of jobs Example:
done. Input:
Input: 2
The first line of input contains an integer T denoting 4
the number of test cases. Each test case consist of 1 4 20 2 1 10 3 1 40 4 1 30
an integer N in first line denoting the number of 5
jobs and the next line consist of Job id, Deadline 1 2 100 2 1 19 3 2 27 4 1 25 5 1 15
and the Profit associated to that Job. Output:
Output: 2 60
Output the number of jobs done and the maximum 2 127
Problem3: Constraints 1 <= T <= 100
Given an array of strings A[], determine if the 0 <= N <= 30
strings can be chained together to form a circle. A 0 <= A[i] <= 10
string X can be chained together with another string Examples
Y if the last character of X is same as first Input
character of Y. If every string of the array can be 2
chained, it will form a circle. 3
For eg for the array arr[] = {"for", "geek", "rig", abc bcd cdf
"kaf"} the answer will be Yes as the given strings can 4
be chained as "for", "rig", "geek" and "kaf" ab bc cd da
Input Output
The first line of input contains an integer T denoting 0
the number of test cases. Then T test cases 1
follow. Explanation:
The first line of each test case contains a positive Testcase 1: Only strings "abc" and "cdf" follows the
integer N, denoting the size of the array. pattern chaining strings together but not "bcd" as
The second line of each test case contains a N space none of other two strings begin with the character
seprated strings, denoting the elements of the 'd'. Thus formation of circle of strings fails.
array A[]. Testcase 2: Every string is given such that, first and
Output last character follows chaining pattern to form circle
If chain can be formed, then print 1, else print 0. of strings.
Session 6
Problem1: Constraints: 1 ≤ T ≤ 100
Given an array of integers where each element 1 ≤ N ≤ 107
represents the max number of steps that can be 0 <= ai <= 107
made forward from that element. Write a function Example:
to return the minimum number of jumps to reach Input:
the end of the array (starting from the first 2
element). If an element is 0, then cannot move 11
through that element. 13589267689
Input: 6
The first line contains an integer T, depicting total 143267
number of test cases. Then following T lines Output:
contains a number n denoting the size of the array. 3
Next line contains the sequence of integers a1, 2
a2, ..., an. Explanation: Testcase 1: First jump from 1st
Output: element, and we jump to 2nd element with value 3.
For each testcase, in a new line, print the minimum Now, from here we jump to 5h element with value
number of jumps. If answer is not possible print -1. 9. and from here we will jump to last.
Problem2: Example:
Given a string S consisting of opening and closing Input:
parenthesis '(' and ')'. Find length of the longest 2
valid parenthesis substring. ((()
Input: )()())
First line contains number of test cases T. Each test Output:
case have one line string S of character '(' and ')' of 2
length N. 4
Constraints: Explanation:
1 <= T <= 500 Testcase 1: Longest valid balanced parantheses is ()
1 <= N <= 105 and its length is 2.
Problem3: Constraints:
Given a Cirular Linked List split it into two halves 1<=T<=100
circular lists. If there are odd number of nodes in 2<=N<=100
the given circular linked list then out of the resulting Example:
two halved lists, first list should have one node Input:
more than the second list. The resultant lists should 2
also be circular lists and not linear lists. 3
Input: 157
You have to complete the method which takes 3 4
argument: The address of the head of the linked 2615
list , addresses of the head of the first and second Output:
halved resultant lists.. You should not read any 15
input from stdin/console. There are multiple test 7
cases. For each test case, this method will be called 26
individually. 15
Output:
Set the *head1_ref and *head2_ref to first resultant
list and second resultant list respectively.