Java: Continuous Median

Level : Intermediate
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:25:00

Lab Details

Difficulty Level: EASY

Problem Statement:

An integer array is given to you. Compute the median of the elements traversed so far in the input array. For the sake of simplicity, assume that there are no duplicates.

Input:

int arr[] = {17, 11, 15, 13, 10, 12, 18, 19, 1, 16, 14, 20};

Output:

Median after reading element 17 is: 17

Median after reading { 17 } elements is 14.0

Median after reading { 17 11 } elements is 15.0

Median after reading { 17 11 15 } elements is 14.0

Median after reading { 17 11 15 13 } elements is 13.0

Median after reading { 17 11 15 13 10 } elements is 12.5

Median after reading { 17 11 15 13 10 12 } elements is 13.0

Median after reading { 17 11 15 13 10 12 18 } elements is 14.0

Median after reading { 17 11 15 13 10 12 18 19 } elements is 13.0

Median after reading { 17 11 15 13 10 12 18 19 1 } elements is 14.0

Median after reading { 17 11 15 13 10 12 18 19 1 16 } elements is 14.0

Median after reading { 17 11 15 13 10 12 18 19 1 16 14 } elements is 14.5


Self-paced Membership
  • 22+ Courses
  • 750+ Hands-On Labs
  • 200+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A
  • 10+ Real-world Projects
  • Career Coaching
  • Email Support
Upto 66% OFF
KNOW MORE..

To get full access to all courses

Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this