Islands in a two dimensional array

Each element in the array is connected to eight other elements (toward top, down, left and right). For example, the zero below is connected to […]

Hamming distance

Write code to calculate hamming distance between two strings. Hamming distance between two strings of equal length is equal to the total number of positions […]

Array of products except the current elements

Given an array of integers, create another array whose i‘th element contain the product of all the elements in original array except the i’th element in original […]

Number of possible triangles from given array of numbers

Given an array of numbers, write an algorithm to count how many triangles are possible with three numbers from array as their side. If input […]

Transpose of non-symmetric matrix

Given a M*N order matrix, which is stored in an array in a row-major order. eg. if the  matrix is of order 2*4 with below […]

Find non repeating number

Given an array of numbers where each number is repeating thrice. In that array one element is not repeating at all. Find that number. Input […]

Find number occurring odd number of times in an array

Given an array of positive integers in which each number is repeated even number of times, except one which is repeated odd number of times. […]

Kadane's Algorithm to find maximum subarray sum

Given an array of n integers (both +ve and -ve). Find the contiguous sub-array whose sum is maximum (More than 1 sub-array may have same […]

check if all nodes of a tree has only one child

Given the PreOrder traversal of a binary search tree (in the form of a tree), check if all the nodes (except the last) of the […]

Comparison of sorting algoritms

Which sorting algorithm makes minimum number of memory write ?