Palindromic Partitioning

Problem Statement Given an integer array,  partitioning the array is said to be a palindrome partitioning if every subarray of the partition is a palindrome. For example, 1 | 2 2 2 | 23 | 4 is a palindrome partitioning of array { 1,2,2,2,23,4 }. You have to find out the fewest cuts needed for palindrome partitioning of a…

Read more...

Hamiltonian Graph – Paper Boy Problem

Shyam needs to distribute newspaper to all the houses while following these rules: He can start from any vertex. When he is on a vertex, he must distribute the newspaper. You can only travel to a vertex that is connected to the current vertex by an edge. You cannot visit a vertex which is already…

Read more...

Maximum Difference in an Array

You are given an array of integers and must compute the maximum difference between any item and any lower indexed smaller item for the possible pairs, i.e., for a given array a find the maximum value of a[j] – a[i] for all i, j where 0 <= i < j < n and a[i] <…

Read more...

Trailing Zeroes in Factorial of a Number – FCTRL – SPOJ

Now we can approach it in 2 ways – the first approach is to calculate factorial of a number and then calculate the number of trailing zeros from the result. But for any value greater than 12 we will see integer exceed. So let’s go with the second approach and Find a relation between number and…

Read more...

SPOJ: PT07Y – Is it a tree

PT07Y – Is it a tree #dfs   You are given an unweighted, undirected graph. Write a program to check if it’s a tree topology. Input The first line of the input file contains two integers N and M — number of nodes and number of edges in the graph (0 < N <= 10000,…

Read more...
Bitnami