0% found this document useful (0 votes)
93 views1 page

Questions PDF

1) Print a 2D array in spiral form, starting from the top left corner and moving clockwise. Examples are provided. 2) Write a function to check if a singly linked list is a palindrome in O(n) time and O(1) space. 3) Duplicate a doubly linked list in which the second pointer of each node can point to any node, not just the previous one, in O(n) time and O(1) space (excluding new list).
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views1 page

Questions PDF

1) Print a 2D array in spiral form, starting from the top left corner and moving clockwise. Examples are provided. 2) Write a function to check if a singly linked list is a palindrome in O(n) time and O(1) space. 3) Duplicate a doubly linked list in which the second pointer of each node can point to any node, not just the previous one, in O(n) time and O(1) space (excluding new list).
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Questions

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).

You might also like