Category Archives: Puzzles

A Very Cool Unix Puzzle

You have a magical program `tux.c’. When you type `cc tux.c’, your compiler appears to hang (i.e, you don’t get back the prompt). Now,during this time, you will be able to type any program `linux.c’ in the standard input and … Continue reading

Posted in Linux, Puzzles | Tagged , , | Leave a comment

array of 0's and 1's. keep 0 at even and 1 at odd places

Q . You are given an array of integers containing only 0s and 1s. you have to place all the 0s in even position and 1s in odd position and if suppose no if 0s exceed no. of 1s or … Continue reading

Posted in Puzzles | Tagged , | Leave a comment

Find majority element in an array

Problem – You have to find a majority element in an array . An element is majority element if it occurs more than half times the size of array. Solution – Take two variables ,major which will contain majority element … Continue reading

Posted in Puzzles | Tagged , | 1 Comment

One duplicate , one missing element in an array

You have an array of size 100 which stores integers from 0 to 99. In this array one number is a duplicate, that means one is missing. How can we find duplicate and missing ?

Posted in Puzzles | Tagged , | 4 Comments

Add two numbers without using +,-,*,/

Method 1 int add(int a, int b) { while(a–) b++; return b; } Method 2 int add(int a, int b) { char *p=a; return &p[b]; } Method 3 By using the concept of binary adders, If p and q are … Continue reading

Posted in Puzzles | Tagged , | Leave a comment

Find the diameter of a tree

Diameter of a tree is the maximum distance between two nodes in a tree. Hence we can see that maximum distance between two nodes will be always between leaf nodes. To find the distance between two leaf nodes, do the … Continue reading

Posted in Puzzles | Tagged , | Leave a comment