Please turn JavaScript on
header-image

Another Casual Coder

Receive updates from Another Casual Coder for free, starting right now.

We can deliver them by email, via your phone or you can read them from a personalised news page on follow.it.

This way you won't miss any new article from Another Casual Coder. Unsubscribe at any time.

Site title: Another Casual Coder

Is this your feed? Claim it!

Publisher:  Unclaimed!
Message frequency:  0.86 / week

Message History

The solution to this problem boils down to finding the next greater element to N in a sorted list. Binary Search is the best mechanism here. Steps:1/ For each element, create a sorted list of its indexes. Store in a hash table for quick access

2/ Create a helper function to find the reverse of a number (in LogN)
3/ Create a helper function to do the Binary Search a...

Read full story

 An interesting problem that can be solved with Tries (there are other solutions too). You can create a simple trie and add all the digits to it. Then the idea is to have a Search function that given the original string and the current index, searches for any match in the trie starting at that index, and if there is a match, returns the jump offset. Complexity becomes th...

Read full story

There are some solutions that take NLogN execution time that are not related to sorting (although a lot of them are). In this case, the problem is fairly simple, it requires processing the digits of a number. A number N on average has LogN digits (for example, Log(999) = 2.999, which is close to 3). Then we have to iterate over N different numbers, for a total complexity of N...

Read full story

Although this problem is labeled as Hard, it is actually easier than it looks. A simple parser with tail-recursion. The only caveat is that I was doing a lot of string manipulation which led to too much memory being used. The solution was to avoid that by passing the indexes of the current processing string as parameters to the functions. That way there won't be any string ma...

Read full story

 This is an interesting problem: you'll be taking advantage that the indexes in an array by definition are already sorted. Hence, although you'll be using the fact that the indexes are sorted, you won't be sorting anything leading to a linear optimized solution. The idea is to keep a list of indexes for each value in the array. The list by definition will be sorted. Then...

Read full story