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.
If we push all of the elements on the list, then we would have to search for the max each time a "3" is called.
By only appending elements that are larger than or equal to your current end of the list (which also happens to be the max of the list), then we always have the max at the end of the list.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
If we push all of the elements on the list, then we would have to search for the max each time a "3" is called.
By only appending elements that are larger than or equal to your current end of the list (which also happens to be the max of the list), then we always have the max at the end of the list.