Traversing a matrix in spiral order

Given a Matrix, write a function that will print the elements in spiral order. For example, if the Matrix is as below: Then the output […]

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

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

Sorting a binary array (which has only 0 & 1)

Given an array which has only 0’s and 1’s. Write an algorithm which will sort this array. (i.e separate 0’s and 1’s by bringing 0’s […]

Shift elements in the array forward by k places

Given an array of m elements and an integer k ( total size of array >= m+k), . Write code to shift all the elements […]