Posts

Showing posts from February, 2011

Check parenthesis

Given an expression like (a+((b+c))) where extra braces are provided on b+c, (b+c) is ok. But ((b+c)) isn’t as it contains redundant. So fr given expression u have to find whether expression contains redundant parenthesis or not.

Train and the flying bird

The distance between Station Atena and Station Barcena is 90 miles. A train starts from Atena towards Barcena. A bird starts at the same time from Barcena straight towards the moving train. On reaching the train, it instantaneously turns back and returns to Barcena. The bird makes these journeys from Barcena to the train and back to Barcena continuously till the train reaches Barcena. The bird finally returns to Barcena and rests. Calculate the total distance in miles the bird travels in the following two cases: (a) the bird flies at 90 miles per hour and the speed of the train is 60 miles per hour.

join vertices of cube to make acute triangle

Think of the 8 vertices of a given cube. You are allowed to join three vertices to form a triangle. How many such unique acute triangles can you make ??

findmin in queue in O(1)

Modify queue data structure to support enqueue() , dequeue() , findmin() .... Is it possible to do this in O(1) with extra space ?

kth largest number

Given an unsorted array of numbers,how will you find kth largest number.

removes duplicates from linked list

How will you remove duplicates from a sorted linked list.

delete the node in linked list

How will you delete a node when a single pointer to that node is given.

Search the index

You are given with an array of integer and the length of array. Now u have to find an index i such that a(i)=i.

next higher number in a sorted array

I have a sorted array ( in ascending order) and I want to find the subscript of a number in the array which is the the next highest number to a given number. For example,if I have 67 as a given number and if I have an array x=(23,36,45,62,79,103,109), then how do I get the subscript 5 from x (to get 79 which is the next highest to 67) without using a  loop?

string contains unique character

Suggest an algorithm to check if a string contains all unique characters.

Output predict

#include int main() { char *p; char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8}; p = (buf+1)[5]; printf("%d \n", p); } Guess the o/p and what if we change p to *p in last printf statement.

Reverse a Stack

Reverse a stack using standard stack operations like push(), pop(), isEmpty().

Remove repeated characters from a string

You are given a string. Develop a function to remove duplicate characters from that string. String could be of any length. Your algorithm must be in space. If you wish you can use constant size extra space which is independent of string size. Your algorithm must be of complexity of O(n). Example: Given string is BANANAS. Output must be BANS. All repeated characters are removed.

switch statement in c

Out of multiple if-else statements and a switch statement, which is faster and why?

Sort a matrix

Given a m*n matrix that is sorted row-wise and column-wise. How would you print the entire matrix in a sorted order ?