Question: There is an array A , consisting of N integers, and two integers, L and R . Your task is to find the shortest fragment
There is an array A consisting of N integers, and two integers, L and R Your task is to find the shortest fragment of consecutive elements of A that contains every integer from L to R inclusive.
Write a function:
class Solution public int solutionint A int L int R:
that, given A L and R returns the length of the shortest fragment of A that contains all numbers from L to R If no such fragment exists, the function should return
Examples:
Given A L and R the function should return The shortest fragment containing the numbers and starts at the third element of A:
Given A L and R the function should return The fragment is the whole array.
Given A L and R the function should return Array A does not contain the number
Write an efficient algorithm for the following assumptions:
N is an integer within the range ;
LSR;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
