## Ice Cream Parlor – Part I

Decided to take a stab at “Binary Search: Ice Cream Parlor” challenge in Hacker Rank. If interested you can get the requirements at the following URL:  https://www.hackerrank.com/challenges/ctci-ice-cream-parlor

The general idea is to solve the sum of two numbers. I will address more on the subject of sum of two numbers on the second part of this post.

It is nice that Hacker Rank has been putting links to short videos with some challenges. In this case there is a video on Binary Search by Gayle Laakmann McDowell author of “Cracking the Coding Interview”. I watched the video. It was simple and to the point. Gayle covers the subject with an implementation using a recursive approach which she then converts to a loop implementation. Continue reading “Ice Cream Parlor – Part I”

## Spiral Matrix

I ran into this challenge described in C/C++ as follows:

#define MATRIX_SIZE 3

#if MATRIX_SIZE == 3

int matrix[3][3] = {

{ 11, 12, 13 },

{ 21, 22, 23 },

{ 31, 32, 33 }

};

#elif MATRIX_SIZE == 4

int matrix[4][4] = {

{ 11, 12, 13, 14 },

{ 21, 22, 23, 24 },

{ 31, 32, 33, 34 },

{ 41, 42, 43, 44 }

};

#else

int matrix[6][6] = {

{ 11, 12, 13, 14, 15, 16 },

{ 21, 22, 23, 24, 25, 26 },

{ 31, 32, 33, 34, 35, 36 },

{ 41, 42, 43, 44, 45, 46 },

{ 51, 52, 53, 54, 55, 56 },

{ 61, 62, 63, 64, 65, 66 }

};

#endif

Given a rectangular matrix of integers [editorial: could be any type of data if one uses generics; I will skip that part] display the values in a spiral fashion. For example, the first matrix[3][3] would produce:  11 12 13 23 33 32 31 11 22. Continue reading “Spiral Matrix”

## LFU Cache I – Single Link List

The motivation for this post was a LeetCode challenge titled:  LFU Cache for which I would like to develop a set of put() and get() methods that operate in O(1) running time. If you wish to take a look at the challenge you may find it at the following URL:  https://leetcode.com/problems/lfu-cache/

The actual challenge does not require O(1) methods but I read the following statement:

Could you do both operations in O(1) time complexity? Continue reading “LFU Cache I – Single Link List”

## Anagrams of a Word

Last week I was talking with a software engineer. While chatting the description of a problem / challenge came up. The description, as far as I can recall, follows:

“Given a text file with all (most would be more precise) English language words in lower-case, find all anagrams for a specified word”.

An example of an anagram was discussed. At the time I was thinking on palindromes and was not able to concentrate on the definition of anagrams. I thought that an anagram consists of a set of letters in any order and letters may repeat. For example, “ana” and “anna” would fit my incorrect definition. I mentioned that I would spend some time on my own and come up with a solution. Continue reading “Anagrams of a Word”