Upload
saifulahmed49
View
225
Download
0
Embed Size (px)
Citation preview
7/30/2019 Byte Mite '08 the Shortest Code Contest
1/15
MCA, Department of Mathematics`
COGNIZANCE 08MCA, Department of Mathematics
Presents
Byte Mite...theshortestcode contest
Team ID: _____________Time:-1 hour
Institute Name: ________
READ INSTRUCTIONS CAREFULLY!!
Instructions:-
1:-This question paper contains 30 questions of 3 levels. 1-10 each 2marks, 11-20 each3
& 21-30 each Que. are 5 marks.
2:- You have to write shortest and efficient code for each question. Codes should be inC/C++ only. No need to including any header file. And don t useany built infunction.
3:- You have to solve all the questions.
4:- Performance of this round will be considered in the final round.
5:- Decision of Judges will be final.
6:-There will not be any negative marking.
.
BEST OF LUCK!!
1
7/30/2019 Byte Mite '08 the Shortest Code Contest
2/15
MCA, Department ofMathematics
Q.1:- find the kth element from the end of a SLL(singly linklist)? (Generalapproach uses a counter and traverses the whole LinkList and again traversesn-k. Try to think something different).
Q.2:- Increment by one without +,- , *, /, ++, --.
Q.3:- What the function do?int magic (int i)
{int j=1337,k=0;do { k -= i += ( i
7/30/2019 Byte Mite '08 the Shortest Code Contest
3/15
MCA, Department ofMathematics
Q.5:- Write a function check (int a, int b) return 0 if a is equal to b, -1 if a is less thenb
& 1 if a is grater than b. Give a single line code. With out using if-else,switch- case, conditional operator.
Q.6:- Write a shortest code to find the sum of product of consecutive odd numbers ina given integer array.
Q.7:- Write statement that takes two integer (a and b) and one character (c)(denoting arithmetic operator +,-,*,/). Perform the arithmetic operation withoutusing Conditional statement and relational operator ().
3
7/30/2019 Byte Mite '08 the Shortest Code Contest
4/15
MCA, Department ofMathematics
Q.8:- perform this task with out using ternary, logical, conditional operator, ifelse, switch-case.change(x, a, b)
{ if(x==a) x=b;else if(x==b) x=a;
}.
Q.9:- As we all know an integer contains 32 bits (generally), so it contains4 bytes. Now you have to write a function haszeroB(n) that tell if n has a zerobyte or not. For example 10 is implemented as 00000000 0000000000000000 00001010 and in this case there are zero bytes so your functionshould return true.
Q.10:- Write a function to find out the length of largest string of 1 s in a given no. E.g.
15ans. is 4, 23 ans. is 3, 22 ans. is 2.
Q.11:- Write a function to Find out Maximum sub-sequence Sum of given integersa1, a2an inO(n) time complexityIf all integers are negative then maximum subsequence Sum is 0.
7/30/2019 Byte Mite '08 the Shortest Code Contest
5/15
4
7/30/2019 Byte Mite '08 the Shortest Code Contest
6/15
MCA, Department ofMathematics
Q.12:- Provide the code that returns a mask that marks the position of the leastsignificant 1 bit in x? You cannot use loops. E.g if x is 10 than ans is 2.
Q.13:- Write a function rtrot(x,i) that return x after right rotation of least significant i bits.
Q.14:- . Write a function convert (n, base) that convert n to the given base.
Q.15:- Write a function nextmultiple (n, m) where m is power of 2, which return nextmultiple of m which is grater or equal to n.
5
7/30/2019 Byte Mite '08 the Shortest Code Contest
7/15
MCA, Department ofMathematics
Q.16:- There is a array of size n storing 0 to n-3 element and 2 are repeated. Find these2 repeated elements in O(n) time complexity with constant space.
Q.17:- ImplementBitwise AND operator& for m,n. don twrite ~ (~m| ~n)
Q.18:- Write a function modify (bool f, int w, int m) that return w modified asif(f) w |= m; else w &= ~m;Without using if, switch, ternary operators and logical operators.
Q.19:-A array has n element which one of the number appear at least 1+ (n/2) times
other numbers can be either repeated or distinct. Find the Element in O (n).
6
7/30/2019 Byte Mite '08 the Shortest Code Contest
8/15
MCA, Department of Mathematics`
Q.20:- Write a function revsfibo(n) that print n no sof Fibonacci series in reverseorder. Without using recursion and any extra space like stack, array.
Q.21:- Write a function that takes integer as argument and return an integer with all thebits in argument are reversed?.(Give at least 2 solutions)
Q.22:- write a function that takes an integer and return as just higher number of that integerWhich have the same no bits are sets? (For ex 3 as input than result is 5 & 5 isInput then result is 6)
7
7/30/2019 Byte Mite '08 the Shortest Code Contest
9/15
MCA, Department of Mathematics`
Q.23:- Write a function that take a integer n and return the result of XOR from 1 to n inCONSTANT time.
Q.24:- Write a function setbit(x, p, n, y) that return x with the n bits that begins at position pset to the rightmost n bits of y.Leaving the other bits unchanged.
E.g. setbit (31, 2, 2, 8) return 25
Q.25:- Write a function count(x, m, n), where x>=0 and 0
7/30/2019 Byte Mite '08 the Shortest Code Contest
10/15
MCA, Department ofMathematics
Q.26:- consider a programint main(){ int i,n=20;
for(i=0;i1000->1001->1010->1011->1100 , (4+1+2+1+3)
9
7/30/2019 Byte Mite '08 the Shortest Code Contest
11/15
MCA, Department ofMathematics
Q.29:- Write a function swap(a,n,i,j) that swap n consecutives bits starting form positioni & j from right.
Q.30:- Consider the following program .int main()
{int i, n;// ADD YOUR DECLERRATIONCin>>n;for(i=0;i>x;// ADD YOUR CODE HERE (Single line code)
}}
1.) Find the second even no assume that at least 2 even no are there.2.) Find the second last even no assume that at least 2 even no are there.
3.) Find the number immediately before the last even number assume that at leastone even number.
10
7/30/2019 Byte Mite '08 the Shortest Code Contest
12/15
MCA, Department ofMathematics
Byte Mite: The Shortest code ContestCognizance 08 @IIT-RoorkeeCoordinator:-Jayesh MahajanFor Solutions Contact [email protected]
1
7/30/2019 Byte Mite '08 the Shortest Code Contest
13/15
1
7/30/2019 Byte Mite '08 the Shortest Code Contest
14/15
MCA, Department ofMathematics
COGNIZANCE 08MCA, Department of Mathematics
Presents
Byte Mite...theshortestcode contest
Final Roundtime 1 hour
READ INSTRUCTIONS CAREFULLY!!
Instructions:-
1:- This question paper has 7 questions that you have to solve on computer.
2:- You have to write shortest and efficient code for each question. Codes shouldbe in C/C++ only.
3:- Marks will be given according to the efficiency of codes.
4:- Decision of Judges will be final.
BEST OF LUCK!!
1
7/30/2019 Byte Mite '08 the Shortest Code Contest
15/15
MCA, Department of Mathematics`
Q.1:- Write a generalize program to print "Hailstone sequence" for a integer.
For ex. If n=13, then sequence is 1,2,4,8,16,5,10,20,40,13(10).
Q.2:- Let two sorted array A[1,...,n] & B[1,...,n] each containing n elements. Write aCode to find out median of all 2n elements in O(logn) time complexity. (10)
Q.3:- Write a Program to calculate x to the power of n, only 2*logn multiplication. (10)
.Q.4:- Write a program to find nth number of the series having exactly k no of set bits.
For ex. If n=5 and k is 2 then ans is 10.(consider only positive integers.)(15)
Q.5:- U have 3 sorted integer Array A, B, C. Find the triplet(x, y, z) of these 3 array wherex is from A, y is from B & z is from C, Which has minimum distance. Distance otriplets is define by MAX(x-y, y-z, z-x)
(30)
Q.6:- There is original array A[n] of n elements. But u are given sum of each pair of 2Numbers i.e. u have n*(n-1)/2 element and 1st element (smallest) .Than write aprogram to find out original Array A. (25)
Q.7:- Given 2 arrays - A and B - each of size 'N' - and it is known that every element inboth of the arrays is either 0 or 1.We have to find the longest interval (p, q) where 0