Posts

FASHION - Fashion Shows

Solution - A[] contains hotness grades for men and B[] contains hotness grades for women. Sort the hotness grades of both men and women in decreasing order. Now, multiply A[i] and B[j] where i == j and add each result.

FCTRL - Factorial

Image
Let look at an example to understand the algorithm Solution - 

ADDREV - Adding Reversed Numbers

Solution

PALIN - The Next Palindrome

Given a number, find the next smallest palindrome larger than this number. For example, if the input number is “2 3 5 4 5”, the output should be “2 3 6 3 2”. And if the input number is “9 9 9”, the output should be “1 0 0 1”. The input is assumed to be an array. Every entry in array represents a digit in input number. Let the array be ‘num[]’ and size of array be ‘n’ There can be three different types of inputs that need to be handled separately. 1)  The input number is palindrome and has all 9s. For example “9 9 9”. Output should be “1 0 0 1” 2)  The input number is not palindrome. For example “1 2 3 4”. Output should be “1 3 3 1” 3)  The input number is palindrome and doesn’t have all 9s. For example “1 2 2 1”. Output should be “1 3 3 1”. Solution for input type 1 is easy. The output contains n + 1 digits where the corner digits are 1, and all digits between corner digits are 0. Now let us first talk about input type 2 and 3. How to convert a given numbe...

Life, the universe, and everything

Hello Guys, the problem is the simplest problem on SPOJ i.e. Life, Universe, and Everything.