Tougher Programming Questions  I
Posted by Subash  10:53 PM
[0] Comments

links to this post
 Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all.
 Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
 Give a oneline C expression to test whether a number is a power of 2. [No loops allowed  it's a simple test.]
 Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution).
 What are the different ways to say, the value of x can be either a 0 or a 1.
 I was given two lines of assembly code which found the absolute value of a number stored in two's complement form. I had to recognize what the code was doing.
 Give a fast way to multiply a number by 7.
 Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
 A real life problem  A square picture is cut into 16 sqaures and they are shuffled. Write a program to rearrange the 16 squares to get the original big square.
 Consider the base 2 representation of numbers. (2 instead of usual +2). Give the condition for a number represented in this form to be positive? Also, if P(A, B) is a function that takes two 01 strings A,B in this representation, when can we say that P(A,B) returns the sum of these two numbers?
 Given an expression tree with no parentheses in it, write the program to give equivalent infix expression with parentheses inserted where necessary.
 Given a maze with cheese at one place and a mouse at some entrance, write a program to direct the mouse to cheese correctly. (Assume there is a path). Following primitives are given: moveforward, turnright, turnleft, iswall?, ischeese?, eatcheese.
 Give me an algorithm and C code to find the subarray with the largest sum given an array containing both positive and negative integers.
 Write a function that returns the factorial of a number.
 Write a function that computes the nth number in the Fibonacci sequence.
 Write an implementation of strlen().
 Switch the integer values stored in two registers without using any additional memory.
 Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
 Write a small lexical analyzer  interviewer gave tokens. expressions like "a*b" etc.
 Write a routine that prints out a 2D array in spiral order!
 How is the readerswriters problem solved?  using semaphores/ada .. etc.
 Write code for reversing a linked list.
 Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) > (1, 3, 5, 9).