0
0
DSA Typescriptprogramming~10 mins

Median of Data Stream Using Two Heaps in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a number to the max heap.

DSA Typescript
maxHeap.[1](num);
Drag options to blanks, or click blank then click option'
Apop
Bpeek
Csort
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of push to add elements.
Trying to use peek which only views the top element.
2fill in blank
medium

Complete the code to balance the heaps when max heap size is greater than min heap size by more than one.

DSA Typescript
minHeap.[1](maxHeap.[2]());
Drag options to blanks, or click blank then click option'
Ashift
Bpop
Cpeek
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using peek instead of pop to remove element.
Using shift which is not a heap method.
3fill in blank
hard

Fix the error in the code to get the median when heaps are of equal size.

DSA Typescript
return (maxHeap.[1]() + minHeap.[1]()) / 2;
Drag options to blanks, or click blank then click option'
Apeek
Bpop
Cpush
Dsort
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() removes elements and changes the heap.
Using push() is for adding elements, not retrieving.
4fill in blank
hard

Fill both blanks to correctly insert a number into the appropriate heap.

DSA Typescript
if (num [1] maxHeap.[2]()) {
  maxHeap.push(num);
} else {
  minHeap.push(num);
}
Drag options to blanks, or click blank then click option'
A<=
B>
Cpeek
Dpop
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of peek() to compare.
Using > instead of <= changes the logic.
5fill in blank
hard

Fill all three blanks to rebalance heaps when min heap size is greater than max heap size.

DSA Typescript
if (minHeap.size() > maxHeap.size() + [1]) {
  maxHeap.[2](minHeap.[3]());
}
Drag options to blanks, or click blank then click option'
A1
Bpop
Cpush
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 1 for size difference check.
Using pop and push in wrong order.