Golang remote profiling and flamegraphs

Quite often we are found with a challenge to troubleshoot something in production, or to see why is our application slow, or why isn’t it serving requests fast enough.

We can use golang tool pprof to troubleshoot our system.

Exposing metrics in your golang application

A lot of times it’s useful to expose metrics for your application so you can know what is going on with the application, there are two ways you can do this one it’s either using a pull or a push mechanism.

Golang has a package called expvar that provides a standardized interface to public variables, such as operation counters in servers, and exports these variables via HTTP in a JSON format.

Sum Two Values

Given an array of integers and a value, determine if there are any two integers in the array which sum equal to the given value.

Merge Overlapping Intervals

Given an array (list) of intervals as input where each interval has a start and end timestamps. Input array is sorted by starting timestamps. You are required to merge overlapping intervals and return output array (list).

Consider below input array. Intervals (2, 10), (4, 12), (11, 13), (15, 20) are overlapping so should be merged to one big interval (2, 13). Similarly interval (15, 20) doesn’t overlap anywhere so it should be added to the merged overlapping interval list.

Finding maximum in a sliding window

So I’m trying to stay true to my resolution, write one or more article about algorithms and datastructure everyday to refresh my memory on how everything works.

Binary search algorithm, find the index of a given key

It’s been a while since I’ve been writing on the blog, so I’ve decided to start being more active and since it’s been almost 15 years since I’ve studied this in University, it can also be a good refreshment course for me as well as anyone else looking into refreshing their memory or learning.

Binary search is a very useful algorithm, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array.