Posts

Subarray with given sum   Given an unsorted array  A  of size   N   of non-negative integers, find a continuous sub-array which adds to a given number   S . Input: The first line of input contains an integer  T  denoting the number of test cases. Then  T  test cases follow. Each test case consists of two lines. The first line of each test case is  N  and  S , where N is the size of array and S is the sum. The second line of each test case contains  N  space separated integers denoting the array elements. Output: For each testcase, in a new line, print the  starting and ending positions ( 1  indexing) of  first such occuring subarray from the left  if sum equals to subarray, else print  -1 . Constraints: 1 <= T <= 100 1 <= N <= 10 7 1 <= A i  <= 10 10 Example: Input: 2 5 12 1 2 3 7 5 10 15 1 2 3 4 5 6 7 8 9 10 Output: 2 4 1 5 Explanation ...
Secondary Factorial Factorial of an integer n,  denoted as n! is defined as the product of the first n natural numbers n! = 1*2*3....*n 1! = 1 and 0! = 1 We define a secondary factorial of a number n, denoted by SF(n), as follows: SF(n) = 1*3*5*....*n, if n is odd and SF(n) = 2*4*6*....*n if n is even If n is an odd number, SF(n) is defined as the product of all the odd numbers, starting from 1, till the number n. SF(5)= 1*3*5= 15. If n is an even number, SF(n) is defined as the product of all the even numbers, starting from 2, till the number n. SF(6)=2*4*6=48. Given a number k, write a code to compute SF(n), where k = n!.  For the given number k, If there is no number n such that  n! = k then, your code should print -1. Illstration Given k = 24 then 24 = 4! and SF(4) = 2* 4 = 8. Given k=25, there is no number n such that 25 = n!, then the out put should be -1. Given k=6, 6=3!. SF(3)=1*3=3 Input Format First line contains an intege...