Category Archives: Algorithm

Multiples of 3 and 5 without using % operator

Write a short program that prints each number from 1 to n on a new line. For each multiple of 3, print “Multiple of 3” instead of the number. For each multiple of 5, print “Multiple of 5” instead of the number. For numbers which are multiples of both 3 and 5, print “Multiple of… Read More »

Find number of endless points

Given a binary N x N matrix, we need to find the total number of matrix positions from which there is an endless path. Any position (i, j) is said to have an endless path if and only if all of the next positions in its row(i) and its column(j) should have value 1. If… Read More »

The prisoner’s dilemma in Game theory

Two members of a criminal gang are arrested and imprisoned. Each prisoner is in solitary confinement with no means of communicating with the other. The prosecutors lack sufficient evidence to convict the pair on the principal charge. They hope to get both sentenced to a year in prison on a lesser charge. Simultaneously, the prosecutors… Read More »

Serial Sort v/s Parallel Sort in Java

We often need to sort array while programming. For this, we use inbuilt method provided by Java in Arrays class i.e sort(). sort() method uses merge sort or Tim Sort to sort the array elements. In both the cases sort() method sequentially sort the elements of an array. In Java 8, there is a new… Read More »