Showing posts with label Get K Min. Show all posts
Showing posts with label Get K Min. Show all posts

Find min element in Sorted Rotated Array (With Duplicates)

Problem: Find the minimum element in a sorted and rotated array if duplicates are allowed:
Example: { 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 2}   output: 0
Algorithm:

Find min element in Sorted Rotated Array (Without Duplicates)

Problem: Find the minimum element in a sorted and rotated array if duplicates not allowed:
Example: {3, 4, 5, 6, 7, 1, 2} output: 1

Get K Max and Delete K Max in stream of incoming integers

Get K Max and Delete K Max in stream of Incoming Integers 

Solution 1 : Using Min Heap

Algorithm :
1) Keep a Min & Max Heap of K size
2) Store first K elements in them.
3) If a new element comes with smaller or larger than root then reorder   heap.