We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
so, what is your time complexity of your method? consider the worst case, you have to compare each former number, so O(n) for each input. when n is big, your algorithm will become more and more slower in linear. In fact, you do not need the binary search tree and you do not have to compare each pair of numbers even in the worst case. in fact, you only care about the numbers in the middle of the input array, using 2 heaps, the time complexity is O(logn) for each input. the hardest point may be which heap should be inserted in and what adpation should be made when the new input comes.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Find the Running Median
You are viewing a single comment's thread. Return to all comments →
so, what is your time complexity of your method? consider the worst case, you have to compare each former number, so O(n) for each input. when n is big, your algorithm will become more and more slower in linear. In fact, you do not need the binary search tree and you do not have to compare each pair of numbers even in the worst case. in fact, you only care about the numbers in the middle of the input array, using 2 heaps, the time complexity is O(logn) for each input. the hardest point may be which heap should be inserted in and what adpation should be made when the new input comes.