STRING ROTATION


Input:

rhdt:246, ghftd:1246

Output:

trhd, ftdgh

Explanation:

Here, every string (rhdt : 1246) is associated with a number, separated by semicolon, if sum of square of digit is even the rotate the string right by 1 position. If square of digit is odd the rotate the string left by 2 position.  

For first case: 

2*2+4*4+6*6=84 which is even so rotate string, rotate right by 1 so ”rhdt” will be “trhd”

For second case: 

1*1+2*2+4*4+6*6=85 which is odd so rotate string left by 2 so “ghftd” will be “ftdgh”

LONGEST SUBARRAY



One have to find the longest subarray such that its element satisfies the following condition:

  x[i]=x[i‐ 1]+x[i-2]   

If more than one subarray of is found of maximum length one has to print the array which starts with the minimum element and if they are also same then the array with minimum second element and so on.   If no subarray is found one has to print ‐1. 

Input:

3, 5, 8, 2, 19, 12, 7, 11

Output:

2, 5, 7, 12, 19

MATRIX WITH HIGHEST SUM


Take string input then form all possible mXm square matrix, and print the matrix with maximum sum. In case, two or more square matrix has maximum sum then print largest matrix followed by next largest matrix and so on. In case, more than one matrix has same size print in order of their occurrence.  

INPUT: 

6, 3, 6, 20, 3, 6,-15, 3, 3

OUTPUT:           

6 3 6         
20 3 6        
-15 3 3 
                 
6 3          
6 20                     

6 20          
3 6

Explanation:-  

6 3 6 
20 3 6 -> its sum is 35 and is order 3*3,
-15 3 3

6 3
6 20 -> its sum is 35 and is order 2*2,

6 20
3 6 -> its sum is 35 and is order 2*2,

DISTRIBUTE BOOKS | Code vita 2019

Problem Description  For enhancing the book reading, school distributed story books to students as part of the Children’s day celebration...