Coding round questions
-
You have been two integers n and m where n is the size of the array and m is the number of the edges. The next line contains an array of size n and next m lines contain two integers x and y each which represents that there exists a bidirectional edge between x and y. We have to output the number of permutations of the array which are lucky. A permutation is said to be lucky if for every Vi in the array there exists an edge between Vi and Vi+1.
Eg Input : 3 2 Output : 2 ( 1-2-3 and 3-2-1)
1 2 3
1 2
2 3
-
You have been an integer n and an array of size n as input. You have to print the count of special numbers in an array. A number is said to be special if it is divisible by at least one other element of the array.
Eg: Input: 3 Output: 2 ( 2 and 3 because they are divisible by 1)
1 2 3
-
You have been given an mXn matrix and an integer k as input. You have to print the count of all the submatrices of the current matrix whose sum is divisible by k.
Eg Input: 2 2 2 Output: 5 ( [1,3], [2,4], [2], [4], [1,2,3,4] )
1 2
3 4
-
You have been given an integer n and a string of length n. You have to find the longest palindromic substring for every prefix of the given string.
Eg. Input: 5 Output: 1 1 3 3 5
a b a b a ( a: 1, a b: 1, a b a: 3, a b a b: 3, a b a b a: 5)