Count Frequency of a Number in a Sorted Array

Count Frequency of a Number in a Sorted Array.

Given a sorted array and a number k. We have to write a code to count how many times a number k appears in a sorted array.

For example –

Input: { 1, 4, 7, 8, 8, 11, 11, 11, 11, 12, 13 }, k = 11

Output: 4

In this input array, The number 11 appears Four time.

Minimum Size Subarray Sum

Minimum Size Subarray Sum (Smallest subarray whose sum is greater than or equal to target).

Given an array of positive integers and a positive number k. Find the smallest contiguous subarray whose sum is either greater than or equal to k. If no subarray is found then return 0.

For example –

Example 1 –

  Input :  {7, 2, 1, 1, 6, 5},  k = 11

Output:  2 ( subarray {6, 5} has the minimum length )

Example 2 –

  Input : {1, 4, 3},   k = 12

Output: 0 (No subarray is possible)