## 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: