Count and print all Subarrays with product less than K in O(n)

Objec­tive:  Given an array of positive integers and integer ‘K’. Write an algorithm to count all the possible sub arrays where product of all the elements in the sub array is less than k. Example: Int [] nums = {10, 4, 2, 6}; K = 100 Output: 9 Sub arrays: [10], [10 4], [10, 4, 2], … Read more Count and print all Subarrays with product less than K in O(n)

Sliding Window Algorithm (Track the maximum of each subarray of size k)

Objective: Given an array and integer k, write an algorithm to find the maximum element in each subarray of size k. Example: int [] nums = { 1, 2, 3, 2, 4, 1, 5, 6,1}; Output: 3, 3, 4, 4, 5, 6, 6 Subarrays – [1, 2, 3], max = 3 [2, 3, 2], max … Read more Sliding Window Algorithm (Track the maximum of each subarray of size k)

Deque Implementation – Java

Java Deque Interface – It’s a linear collection. The Deque interface is a subtype of the util.Queue interface. Deque is acronym of “Double Ended Queue” means it supports insertion and removal of data from both the ends. So it can be used as Stack OR Queue. Declaration public interface Deque extends Queue Methods: Return Type Method Description boolean add(E e)  Insert … Read more Deque Implementation – Java