Reversing a Singly Linked list

Given a Singly linked list, write an iterative (non-recursive) function to reverse the linked list.

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 […]

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 […]

Number of nodes in a binary tree of height h

Given a binary tree of height ‘h’. What will be the minimum and maximum number of nodes in the tree?

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 […]

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 […]

Check if a linked list is palindrome

Write a function to check if a Singly linked list is a palindrome or not. For example, the linked list 2 -> 3 -> 4 […]

Mirror of a Binary Tree

Given a Binary Tree, write a function which will convert that tree to its Mirror Tree. For Example: If the Binary Tree is 1 / […]

Non-leaf nodes of a binary tree

Write a function that will return the number of non-leaf nodes in a binary tree. For example: The below binary tree A / \ B […]

Compute polynomial, Cn.x^n + Cn-1.x^(n-1) + … … + C2.x^2 + C1.x + C0

Write an effective algorithm to compute the value of below polynomial for a given value of x :  F(x) = Cn.xn + Cn-1.xn-1 + Cn-2.xn-2 […]