Print all diagonals of a matrix in alternate order
Given a square matrix of order N*N, write code to print all the elements in the order of their diagonal in alternate forward and backward order. For example, in the below matrix, the elements should be printed in the marked (in red) order, and the final output should be as shown below: Note that the […]
Compare to strings given as linked list
In C language, string library has a function strcmp that takes two arguments and return -1, 0 or 1 depending on whether first string is less than equal-to or greater than the second string. int strcmp(const char *str1, const char *str2); Write similar function that compare strings given in the form of linked list, For […]
Find minimum and maximum value in a tree
Given a Binary tree (not BST), write code to find the minimum and maximum value in the tree. For example, if the tree is as shown in the picture, then the output should be: Minimum: 2 Maximum: 20
Prisoners and the lightbulb puzzle
There are 10 prisoners are in 10 different cells of a prison. There is no way in which they can communicate with each other. Each night, the warden picks one of the 10 prisoners and that prisoner is supposed to spend the entire night in the central living room. There is one bulb in the living […]
Code to evaluate a postfix expression
Given an expression in postfix notation, write code to evalute a mathematical expression given in postfix notation. For Example: Input: 4 2 3 + * 6 – Output: 14
Code to convert In-Fix to postfix notation
Given an arithmetic expression in in-fix notation. Write code to convert that algorithm in corresponding post-fix notation. For example: Infix Postfix —— ——– a+b ab+ (a+b)*c ab+c* a+b*c abc*+ a*(b+c)-d/e abc+*de/-
Logic Puzzle: Inverting the glasses
Four glasses are placed on the four corners of a square rotating table. Each glass is either upright (up) or upside-down (down). You have to turn all the glasses in same direction (either all up or all down). There are following conditions You are blindfolded, At one time you can only change two glasses (and […]
Interview Puzzle: Heaven or Hell
You are standing before two closed doors. One of the doors leads to heaven and the other one leads to hell. Two watchmen are standing, one in front of each door. You know one of them always tells the truth and the other always lies, but you don’t know which watchman tells the truth and who is the liar. […]
Upstream-Downstream relative speed question
A person rides a cycle at a constant speed. When he drives in the direction of the wind, he is able to go 35 km in 5 hrs. While returning, when the wind was against the direction of his driving, he took 7hrs for the same distance. At what speed does he rides when there is no wind?
Minimum number of platform required for a railway station
Given arrival and departure times of all trains for a particular railway station, write code to find the minimum number of platforms required on that railway station, so that all trains can run according to their schedule.