Funny String

It is Sunday in the Twin Cities of Minneapolis and St. Paul and it is starting to snow. The forecast calls for snow turning into rain. Later this morning my wife and I are going to the Mall of America (MOA) for a walk. It beats getting on exercise equipment at home and watching TV.

I selected the Funny String practice from HackerRank. Given a string one has to reverse the characters and place them in a second string. Then traverse both comparing the absolute differences among consecutive characters. If the differences match then the function should return the string “Funny”; otherwise it should return “Not Funny”. Continue reading “Funny String”

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”

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”

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”

Missing Numbers

I received a message to solve the Missing Numbers challenge from HackerRank. The approach is to read the first list (A) to a HashMap so we would be able to get a count for each key. The process repeats with the second list (B). At that point we can iterate over list A (smaller) and update (subtract) or delete the matching keys from list B (larger). What is left in B is what is needed. Continue reading “Missing Numbers”