Given a list of millions of words, design an algorithm
Many problems involving a dictionary can be solved by doing some pre-processing. Where can we do preprocessing? Well, if we’re going to create a rectangle of words, we know that each row must be the same length and each column must be the same length. So let’s group the words of the dictionary…
Design an evacuation plan of San Francisco residents
This challenge has a common sense. In 2006, Kansas was assigned Grade A (highest) on the Emergency Evacuation Report Map compiled by the American Highway Users Union. New Orleans hit by Hurricane Katrina got D. What is the score for San Francisco? F. New York, Chicago, and Los Angeles have also got this score….
The task of the cashier-developer
This task was given during the interviews at Apple. Imagine you got a job as a cashier in a store. Your boss accidentally found out that you have the development skills, and wanted you to help him create an application. Input data: A specified amount of money. An array with all available coins’…
Create a lock class to prevent deadlock
There are several common options to prevent deadlock. One of the most popular is to explicitly declare what lock is required. This way, we will be able to check whether the created lock is a deadlock and if so, we can stop working. Let’s take a look and sort out the way we…
Create a method that counts a number
As usual, initially, we try to solve the task bluntly. /* Count the number ‘2’ between 0 and n */ int numberOf2sInRange(int n) { int count = 0; for (int i = 2; i <= n; i++) { // We can begin with 2 count += numberOf2s(i); } return count; } /* count…