C program output

What will be the output of the below C language program: int main() { enum os {windows, unix, mac}; enum furnitures {doors, windows, table, chair, bed}; for(int i=doors; i<bed; i++) printf(“%d “, i); return 0; }

Pass by Reference v/s Pass by value

In C language, everything is pass-by-value and C++ supports that. But C++ also provides provision to pass arguments by reference (by declaring new reference data type). When should we use pass by reference. Will it have an impact on the performance if I pass by value or it is just another way to return more […]

Rotating an array around a pivot

Given an Array of (say) integers like below: 1 2 3 4 5 6 7 8 and an index, say, 2. Write a function which will rotate the array around index 2. i.e the output should be: 3 4 5 6 7 8 1 2

Compute Max and Min without branching

Given 2 unsigned integers, write expressions to find the maximum and minimum of these 2 integers without using either if-else or conditional operator.

Diameter of a Tree

Diameter of a tree is the longest path (Number of nodes) between two leaf nodes of the tree. It is also called width of the tree. For example, diameter of the below tree is 6 (red color nodes form part of the diameter) A / \ B C / / \ D E F \ […]

Permutations of a String or Array

Print all possible permutations of an Array or a String. For Example: If the array is arr={1, 2, 3}. Then the possible permutations are: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1

Minimum path sum in a matrix

Given a Matrix of positive integers and 2 cells A & B. You have to reach from A to B covering cells such that the sum of elements in path is minimum. You can travel in forward, downward and diagonally. For example: If the given Matrix is as below: 1 2 3 4 8 2 […]