Professional Documents
Culture Documents
Coding Block Questions
Coding Block Questions
Compute the minimum number of switches you need to make in order to turn off all the
Bijlibulbs.
Input Format
The input contains a single string of values from the set {0,1}. N is equal to the length of the
string, and each Bijlibulb is represented by a char. A Bijlibulb that is switched off is
represented by a 0, and one that is switched on by a 1.
Constraints
1 ≤ N ≤ 50.
Output Format
The output should contain a single number representing the minimum number of switches
needed.
Sample Input
1011
Sample Output
13
You are given a number n, denoting number of vertical fences of width 1metre. In the
next row, you will be given height of each fence in metres. Now you want to paint these
fences in minimum number of horizontal strokes or vertical strokes possible. During one
stroke, the brush should touch fence at all times. You can paint the same area multiple
times.
Input Format
Constraints
Output Format
Sample Input
5
2 2 1 2 1
Sample Output
3
Explanation
1st stroke : Horizontally along all the planks 2nd stroke : horizontally on 1 and 2 3rd
stroke : horizontally/vertically on 4
2 y : Find the spectral value of subarray a1 , a2 …. ay, which is defined as product of (c[p]+1)
(c[p]+1)
for all p.
Here c[p] is the number of times p occurs in the subarray [a1 , a2 …. ay], where p takes the
value of each of the distinct elements present in the subarray.
Input Format
First line of input contains n and q, the number of queries to be performed. Next q lines
consists of queries in the aforementioned format.
Constraints
1 ≤ n ≤ 10^5
1 ≤ q ≤ 10^5
1 ≤ x, y ≤ n
Output Format
For each query of type 2, output the spectral value modulo 109 + 7, in a new line.
Sample Input
8 5
1 3 5
2 2
2 6
1 1 4
2 8
Sample Output
27
186624
13176688
Explanation
In the second query, subarray [0,0] is considered. Since 0 occurs twice, the spectral
value becomes (2+1)(2+1)=27
In the third query, in subarray [0,0,5,0,0,0], the spectral value becomes (5+1) (5+1)*(1+1)
(1+1)
= 186624, since 0 appears five times and 5 appears once in the subarray.
In the fourth query, the array becomes [4,0,5,0,0,0,0,0].
Similarly, in the fifth query, in subarray [4,0,5,0,0,0,0,0], the spectral value becomes
(6+1)(6+1)*(1+1)(1+1)*(1+1)(1+1) = 13176688.
Thor made an escape plan from Sakaar Planet with Bruce Banner. He told Bruce that they
will find the Quinjet and fly their way along to Asgard easily. But Banner told Thor that in
order to fly Quinjet Thor has to solve a puzzle. Given a number A, Thor is supposed to find
the count of numbers that are when added to A or Xored(Bitwise Xor) with A gives the same
value. Thor is supposed to print the total count of such numbers.
Input Format
A single integer, A
Constraints
0 ≤ A ≤ 10^15
Output Format
Sample Input
5
Sample Output
2
Explanation
You notice that in this method the cells get uneven coatings. You set out to prove this.
Input Format
Constraints
1 ≤ T ≤ 10
1 ≤ a, b ≤ 100
1 ≤ n ≤ 10^18
1 ≤ x ≤ a
1 ≤ y ≤ b
Output Format
For each test case print three integers: the maximum coatings on a cell, the minimum coatings
on a cell and coatings on the cell of the xth row and yth column.
Sample Input
2
3 2 15 2 2
4 1 8 3 1
Sample Output
4 2 3
3 1 2