# Archive for December 2016

Problem statement We define to be a permutation of the first natural numbers in the range . Let denote the position of in permutation (please use -based indexing). is considered to be an absolute permutation if holds true for every . Given and , print the lexicographically smallest absolute permutation, . . . Read more

I was searching the net for a very, very simple token field for AngularJS the other day to use on a side project that I was working on. Unfortunately I couldn’t find anything that suits my requirements. So I implemented my own. Here is how to use it. (Optional) Install . . . Read more

Problem statement Consider a string, , of lowercase English letters where each character, , denotes the letter at index in . We define an palindromic tuple of to be a sequence of indices in satisfying the following criteria: , meaning the characters located at indices and are the same. , . . . Read more

Problem statement Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has packets of candies and would like to distribute one packet to each of the children in the village (each packet may contain different number of candies). To avoid a fight between the . . . Read more

Problem statement Whenever George asks Lily to hang out, she’s busy doing homework. George wants to help her finish it faster, but he’s in over his head! Can you help George understand Lily’s homework so she can hang out with him? Consider an array of distinct integers, . George can . . . Read more

Problem statement After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a circle. That means the first house is the neighbor of . . . Read more

Problem statement You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two . . . Read more

Problem statement The National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to the client’s median spending for the last days, they send the client a notification about potential . . . Read more

Problem statement Sort the letters (lowercase a-z) in one word by the order they occur in another word in linear time. Assume all letters of word appear in . Solution What I am implementing is basically a simplified Counting Sort algorithm. Since I know the letters are all lowercase, I . . . Read more

Problem statement In this challenge you need to print the data that accompanies each integer in a list. In addition, if two strings have the same integers, you need to print the strings in their original order. Hence, your sorting algorithm should be stable, i.e. the original order should be . . . Read more