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.
Agree. Not sure how it's passing with an ArrayList without timing out.
However, I think the algorithm would work if you changed the ArrayList to LinkedList. Insertion in a LinkedList would take O(1). Total complexity would be O(n log(n)). O(n) for the elements traversal. Log(n) for the Binary Search.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Heaps: Find the Running Median
You are viewing a single comment's thread. Return to all comments →
Agree. Not sure how it's passing with an ArrayList without timing out. However, I think the algorithm would work if you changed the ArrayList to LinkedList. Insertion in a LinkedList would take O(1). Total complexity would be O(n log(n)). O(n) for the elements traversal. Log(n) for the Binary Search.