Tag Archives: queue

Cycle queue

This is a practice for cycle queue. Cycle queue uses array to store elements. Main character of cycle queue is that it allocate space for one time. When deQueue and enQueue, it saves time for space allocation compared to normal queue. Disadvantage is that the lenght is constant once it initializes. package jan; public class… Read More »

Queue with min and max value

I’ve read the Queue with min and max value code from Junmin Liu link. The one he mentioned is really good idea. It uses 2 stacks to keep the min/max for queue. This problem is orignated from the count bound sliced problem. For that problem, I used another way to implement. By that, I can… Read More »

Count bounded slices 2 – O(n) solution

This is the O(n) solution, without result permutation output. Thanks to the answer from careerup link. I wrote my understanding and analysis. The basic idea is that we start with arr[0] and then see how many more elements you can include before you violate the max-min<=k constraint. When it reaches some index ‘end’ you can… Read More »

Count bounded slices

Problem: Return the pair of indices that forms the slice where the difference between the maximum and minimum in the slice <= k. Pair of indices shouldn’t be like (i,i). Consider k is 2. And the array is 3 5 7 6 3. Output: (0,1) (1,2) (1,3) (2,3) Analysis: A brute-force idea is to recursively find… Read More »