Print all possible solutions to N Queens problem

The N queens puzzle is the problem of placing N chess queens on an N × N chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal.

Stack implementation in Java

  This article covers the stack implementation in Java. A stack is a linear data structure which follows the LIFO (last-in first-out) principle. That means the objects can be inserted or removed only at one end of it also called as top.

Sieve of Eratosthenes

Sieve of Eratosthenes is a very efficient algorithm that can be used in most coding competitions involving prime numbers in the range of a given number n.   The algorithm starts off by assuming that all the numbers in the range 2 to n are prime. Now we traverse the list starting from 2 to …

Program to find n’th Fibonacci number

Write a program to calculate n’th Fibonacci number where n is a given positive number.   Fibonacci sequence is characterized by the fact that every number after the first two is the sum of the two preceding ones. For example, consider below sequence – 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, …

Queue implementation in java

  A queue is a linear data structure which follows the FIFO (first-in first-out) principle. That means the object which is inserted first will be the first one out, followed by the object which was inserted next. The queue supports below core operations –

Find numbers represented as sum of two cubes for two different pairs

Given a large number N, find all positive numbers less than N that can be represented as sum of two cubes for at-least two different pairs.   In other words, find all positive numbers M less than given number N that can be expressed as M = (a^3 + b^3) = (c^3 + d^3) for …