Close

## Minimum number of symbols to change to make a chain

Given a string containing the only symbols ‘+’ or ‘-‘, how do we find the minimum number of changes to transform it to a chain. A chain of length N is the sequence of alternative + and – symbols. For example “+-+-+” is a chain of length 5. Similarly “-+-+-+” is a chain of length…

## Maximum length of subarray with non-zero elements

Given an array of of size N, How do we find the longest sub-array with all non-zero elements? For example consider the array {34, 0, 18, 3, 0, 1, 4, 5, 0, 12}, the longest sub-array with non-zero elements is 3 i.e {1,4,5}. This problem is from Codechef. Follow this link to solve this problem…

## GCD queries

This problem is from Codechef January challenge. Click on the link to try this problem on your own. The problem statement is as follows. Given an array of size N and two indices L and R. We need to find the GCD (Greatest Common Divisor) of all the array elements except in the range [L,R].…

## Permutation cycles – Code chef problem

This is a problem from CodeChef. Follow this link if you want to try this problem on your own. Given a permutation of numbers from 1 to N. You can walk through the permutation to find cycles in it.Here is how you can do it. Consider the permutation {3, 5, 2, 1, 4, 6} Start…

## Birthday candles – Codechef problem

This is from CodeChef practice problems. Follow this link to try on your own! Here is the simplified problem statement. A number of candles are given each of them labelled with the digit 0-9. We have to find the minimum positive number that can not be formed with the given candles.  The input is given…