Questions PDF
Questions PDF
Q1) Given a 2D array, print it in spiral form. See the following examples. Input: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Output: 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 Input: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Output: 1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11 Q2) Function to check if a singly linked list is palindrome. Constraints: time O(n) and space O(1). Q3) You are given a Double Link List with one pointer of each node pointing to the next node just like in a single link list. The second pointer however CAN point to any node in the list and not just the previous node. Now write a program in O(n) time and constant space (except new linked list) to duplicate this list. That is, write a program which will create a copy of this list. Q4) You are given two numbers A and B. Write a program to count number of bits needed to be flipped to convert A to B. Q5) Write a program to swap odd and even bits of a 32-bit unsigned integer with as few instructions as possible. (bit-0 and bit-1 are swapped, bit-2 and bit-3 are swapped and so on).