Given an integer k 0 and an array A of n bits describe an e

Given an integer k > 0 and an array, A, of n bits, describe an efficient algorithm for finding the shortest subarray of A that contains k 1’s. What is the running time of your method?

Can you provide the pseudo code?

Solution

To find the shortest subarray of A that contains k 1’s, the algorithm is as follows:

Time Complexity:

In this algorithm, an array of n elements is traversed, so the time complexity is O(n)

Given an integer k > 0 and an array, A, of n bits, describe an efficient algorithm for finding the shortest subarray of A that contains k 1’s. What is the ru

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site