fave77 / Mathball

A JavaScript library for Competitive Programming
https://fave77.github.io/Mathball-Docs/
MIT License
99 stars 49 forks source link

Find Median #108

Closed fave77 closed 5 years ago

fave77 commented 5 years ago

Do the checklist before filing the issue:

NOTE: Provide a clear and concise description of the feature that needs to be added! Or if its a bug, then provide the necessary steps to reproduce it along with screenshots.

Shubhayu-Das commented 5 years ago

A suggestion: We can implement a general findRank() function first and then use it for this function.

fave77 commented 5 years ago

@sateslayer what would that function do?

Shubhayu-Das commented 5 years ago

Find the number present in the array at any valid rank in O(n) time.

Rank(x) = 1 + {number of numbers >= x)

example: arr = [1, 5, 2, 7, 2, 8] findElementAtRank(3) = 5; findElementAtRank(arr.length) = 1 findElementAtRank(4) = none //Error findElementAtRank(5) = 2 //Both the two's hold equal rank/priority

Therefore, findMedian(arr) = findElementAtRank(arr.length/2); //Separate handling for odd number of elements as per requirement.

Manvityagi commented 5 years ago

I Wanna take up this issue @pbiswas101 !

fave77 commented 5 years ago

@Manvityagi please don't comment under every issue, I've assigned you #109 as per your latest comment. First, decide which one you would like to work on and then claim that issue.

Manvityagi commented 5 years ago

Sorry, I would like to first work on this as I have already almost completed it!

fave77 commented 5 years ago

@Manvityagi why did you started working before being assigned? I'm sorry but first complete the other one and then if no one else claims this issue by then, I'll assign this one to you.

Manvityagi commented 5 years ago

okay!!

fave77 commented 5 years ago

@Manvityagi you're assigned!