Sunteți pe pagina 1din 15

MCA, Department of Mathematics`

COGNIZANCE 08
MCA, Department of Mathematics

Presents

Byte Mite
Team ID: _____________ Time:-1 hour Institute Name: ________

...the shortest code contest

READ INSTRUCTIONS CAREFULLY!! Instructions:1:-This question paper contains 30 questions of 3 levels. 1-10 each 2marks, 11-20 each 3 & 21-30 each Que. are 5 marks. 2:- You have to write shortest and efficient code for each question. Codes should be in C/C++ only. No need to including any header file. And don t use any built in function. 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

MCA, Department of Mathematics` Q.1:find the kth element from the end of a SLL(singly linklist)? (General approach uses a counter and traverses the whole LinkList and again traverses n-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<0) + i; }while( j*=42); return k; }

Q.4:-

Write a code to find the nearest multiple of 8 for a given number. Without using -, *, /, % .if-else and conditional op.

MCA, Department of Mathematics` Q.5:b Write a function check (int a, int b) return 0 if a is equal to b, -1 if a is less then & 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 in a 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 without using Conditional statement and relational operator (<,>).

MCA, Department of Mathematics` Q.8:perform this task with out using ternary, logical, conditional operator, if else, 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 contains 4 bytes. Now you have to write a function haszeroB(n) that tell if n has a zero byte or not. For example 10 is implemented as 00000000 00000000 00000000 00001010 and in this case there are zero bytes so your function should return true.

Q.10:- Write a function to find out the length of largest string of 1 s in a given no. E.g. 15 ans. is 4, 23 ans. is 3, 22 ans. is 2.

Q.11:- Write a function to Find out Maximum sub-sequence Sum of given integers a1, a2an in O(n) time complexity If all integers are negative then maximum sub sequence Sum is 0.

MCA, Department of Mathematics` Q.12:- Provide the code that returns a mask that marks the position of the least significant 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 next multiple of m which is grater or equal to n.

MCA, Department of Mathematics` Q.16:- There is a array of size n storing 0 to n-3 element and 2 are repeated. Find these 2 repeated elements in O(n) time complexity with constant space.

Q.17:- Implement Bitwise AND operator & for m, n. don t write ~ (~m | ~n)

Q.18:- Write a function modify (bool f, int w, int m) that return w modified as if(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).

MCA, Department of Mathematics` Q.20:- Write a function revsfibo(n) that print n no s of Fibonacci series in reverse order. 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 the bits 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 integer Which have the same no bits are sets? (For ex 3 as input than result is 5 & 5 is Input then result is 6)

MCA, Department of Mathematics` Q.23:- Write a function that take a integer n and return the result of XOR from 1 to n in CONSTANT time.

Q.24:- Write a function setbit(x, p, n, y) that return x with the n bits that begins at position p set 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<(m & n)<127, that returns the no of bytes in x whose value is between m & n.

MCA, Department of Mathematics` Q.26:- consider a program int main() { int i,n=20; for(i=0;i<n;i--) printf(*); return 0; } Change / add only one character to print * 20 times (Give at least 3 solutions ) and print 21 character (Give only one solutions).

Q.27:- Write a function that takes array of n integers which contains 1 to n with one is missing and one is duplicated .find out those 2 numbers in O(n) time complexity and constant space .u can visit each index at most one (5)

Q.28:- Write a function flips (n, m) that take two values and return total no of bits flips from n to m assuming increment by 1. For ex. flips (7, 8) ans is 4, flips (7, 12) ans is 11 bcz 0111->1000->1001->1010->1011->1100 , (4+1+2+1+3)

MCA, Department of Mathematics` Q.29:- Write a function swap(a,n,i,j) that swap n consecutives bits starting form position i & j from right.

Q.30:- Consider the following program . int main() { int i, n; // ADD YOUR DECLERRATION Cin>>n; for(i=0;i<n;i++) { cin>>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 least one even number.

1 0

MCA, Department of Mathematics`

Byte Mite: The Shortest code Contest Cognizance 08 @ IIT-Roorkee Coordinator:-Jayesh Mahajan For Solutions Contact to Jayesh30785@gmail.com

MCA, Department of Mathematics`

COGNIZANCE 08
MCA, Department of Mathematics

Presents

Byte Mite
Final Round time 1 hour

...the shortest code contest

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 should be 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!!

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 a Code 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 where x is from A, y is from B & z is from C, Which has minimum distance. Distance of triplets 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 2 Numbers i.e. u have n*(n-1)/2 element and 1st element (smallest) .Than write a program 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 in both of the arrays is either 0 or 1.We have to find the longest interval (p, q) where 0 <= p <= q <= (N - 1), such that (20) A[p] + A[p+1] + A[p+2] + .... + A[q] = B[p] + B[p+1] + B[p+2] + .... + B[q] or simply report that no such interval exists. Desired time complexity = O(N)

jayesh Mahajan jayesh30785@gmail.com

S-ar putea să vă placă și