Non-recursive solution to tower of hanoi

We discussed problem of Tower of Hanoi earlier and written a recursive function to solve the problem, Recursive functions take lot of extra memory (New […]

Tower of Hanoi code

Tower of Hanoi is a Mathematical Game. There are 3 pegs (Rods) and number of discs, each of different size, which can be inserted into […]

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

Implement two stacks in one array

Given a linear memory (in the form of an array). Implement two stacks such that memory is used in an optimal manner. i.e if user […]

Sorting a linked list of 0s, 1s and 2s

Given a Singly linked list with each node containing either 0, 1 or 2. Write code to sort the list. Input List: 1 -> 1 […]

Print first non-repeating character in the string

Given a String where characters are repeating. Write code to print the first character that is repeating later in the string. e.g, Input String: ritambhara […]

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

Rotating a linked list around pivot

We have seen a question to rotate an array around a pivot earlier. Now write similar code for linked list. Given a linked list and an […]