LRU with LinkedHashMap

A day or so ago I saw the Twitter post 246 LRU Cache from LinkedHashMap by Dr. Heinz M. Kabutz. What called my attention was that a few weeks ago I was reading a paper on caching and spent some time (and generated some posts) on the subject LFU Cache I, LFU Cache II and LFU Cache III. Continue reading “LRU with LinkedHashMap”

New, Duplicate or in Segment – Part 4

Ditto. This post covers the continuation of the original proposed (by me) challenge to HackerRank. Seems that I made the mistake to generate the post New, Duplicate or in Segment – Part 2 which describes this challenge. As you can verify I did not suggested a solution. Apparently that was enough to disqualify this entry. Next time I come up with a proposed challenge will not post a thing about it. Continue reading “New, Duplicate or in Segment – Part 4”

New, Duplicate on in Segment – Part 3

I received a message from HackerRank indicating that they would not be able to use the New, Duplicate or in Segment proposed (by me) challenge because I had already made a post in my blog. I thought it would be fine if I did not describe a possible solution. I guess I was wrong.

Within the specified range label each received integer as “New” if the integer is being processed for the first time, “Duplicate” is the integer is not in a segment but has been processed before or “In segment” if the integer is part of a segment of two or more integers. Continue reading “New, Duplicate on in Segment – Part 3”

Guava -BiMap

Guava by Google contains the BiMap class which implements a bi-directional map. On many occasions I have been using a Map and had the need to invert it to use the values as keys. It is doable but somewhat cumbersome. You can always use two maps (key -> value and value -> key) but on many occasions you may run into the issue that the values are duplicated and the second map will have to deal with duplicate keys. This elegant class available in Guava may be of assistance. Continue reading “Guava -BiMap”

Guava – Multimap

Not to be confused with the fruit, Guava is an open source, Java based library developed by Google. It provides utility methods for collections, caching, primitives support, concurrency, common annotations, string processing, I/O, and validations.

I have been experimenting and using the Google Guava library for a few months. Most of features are quite nice and useful (e.g., Multimaps). In this post I show how easy it is interact with multimaps. Continue reading “Guava – Multimap”

More Emphasis on C++

As we all know change is always confronting us. A couple years ago I decided to put a lot more emphasis on polishing on my Java by reading, learning and refreshing concepts.  I will continue to do so but will relegate it to a second plane. For the next few months I will put emphasis on C++. Continue reading “More Emphasis on C++”

Count Luck

I received an email message from HackerRank inviting me to solve the Ice Cream Parlor challenge. It seems like I have already solved the challenge as illustrated in the Ice Cream Parlor – Part II post. On several occasions I have received invitations to solve challenges that I have already addressed. Perhaps HackerRank did not like my solutions ;o)

On this post I will address the Count Luck challenge from HackerRank. You can read in the discussions section how the challenge was initially given an easy difficulty level and then changed to medium. There is a reference to the  Connected Cells in a Grid – Follow Up challenge which I have already solved in this blog. In retrospect, for me this challenge was harder than the one mentioned in the discussion. Continue reading “Count Luck”

Connected Cells in a Grid – Follow Up

Last Friday afternoon I stopped by to donate blood to the Red Cross. I do this twice a year. As usual, I made an appointment. Earlier that day filled the RapidPass, and had a copy of the ticket in my cell phone. The staff at the blood collection site was running behind. After over an hour wait I was called. It took a while to get the process started. The actual donation took no more than 10 minutes. I will be back on fall later this year. Hope the entire process speeds up :o) Continue reading “Connected Cells in a Grid – Follow Up”

Connected Cells in a Grid

I received a message from HackerRank to give the Connected Cells in a Grid challenge a try. If interested, please take a look at the requirements and see if we agree with the approach I took to solve the challenge. Continue reading “Connected Cells in a Grid”

Single Element in a Sorted Array

Ventured into LeetCode and randomly selected the Single Element in a Sorted Array challenge. The requirements are very straight forward. Make sure you pay attention to the following Note: Your solution should run in O(log n) time and O(1) space. Continue reading “Single Element in a Sorted Array”