Largest Rectangle – Part 1

histogramOn and off, during the past couple days I spent time soling the Largest Rectangle challenged form HackerRank (https://www.hackerrank.com/challenges/largest-rectangle). The challenge is described as follows:

“There are N buildings in a certain two-dimensional landscape. Each building has a height given by h in [1 : N]. If you join K adjacent buildings, they will form a solid rectangle of area K * min(h, … , h). Given N buildings, find the greatest such solid area formed by consecutive buildings”. Continue reading “Largest Rectangle – Part 1”

Selection Sort

selection_sortContinue to read and experiment with most of the exercises in the Algorithms fourth edition book by Robert Sedgewick and Kevin Wayne. I am currently reading chapter 2.1 Elementary Sorts. I just finished the section that deals with Selection sort. The subject matter is well described and a set of methods (with possible some exceptions) will be used to implement all the sorting algorithms in this chapter. That is quite nice because it emphasizes on the concept of hiding data and the actual algorithm from clients.

The following methods are common to all sorting algorithms described in the second chapter: Continue reading “Selection Sort”