Hackerrank Interview Questions
- 0of 0 votes
Given a Matrix A,
The rules for movement are as follows :
1. Can only move Right or Down from any element
2. Can only move within the row and column of element we start from intially.
3. You can only visit or cross an element if its value is lesser than the value of element you start from.
Find total number of elements one can visit, If one starts from an element A(i,j) where i-> row and j-> column.
Note : You have to print this output for each matrix element.
Input : Matrix
1 2 3
2 3 1
3 1 2
1 1 3
1 3 1
3 1 1
- 2of 2 votes
We define a subarray of array to be a contiguous block of a's elements having a length that is less than or equal to the length of array a. For example, the subarray of array a = [1,2,3] are , , [1,2], [2,3], and [1,2,3]. Now, let's say we have an integer, k = 3. The subarrays of a having elements that sum to a number <=k are , , and [1,2]. The longest of these subarrays is [1,2], which had a length of 2.
Complete the maxLength function in the editor. It has 2 parameters :
1. An array of integers, a.
2. An integer, k
The function must return the length of the longest subarray elements that sum to a number less than or equal to k.
Locked stub code in the editor reads the following input from stdin and passes it to the function:
The first line contains a single ineteger n, denoting the number of elements in array a.
Each line i of the n subsequent lines (where 0 <=i < n) contains an integer describing elements i in array a.
Each line i of the n subsequent lines (where 0 <= i <= n) contains an integer describing elements i in array a.
The last line contains an integer, k.
1 <= n <= 10^5
1 <= a[i] < 10^3
1 <= k <= 10^9
- 4of 4 votes
You are given a string S and a set of n substrings. You are supposed to remove every instance of those n substrings from S so that S is of the minimum length and output this minimum length.
n=2 - substrings-- ab, cd
ccdaabcdbb -> ccdacdbb -> cabb -> cb (length=2)
Can someone help me with the algo?