brainteaser

Javascript callback functions and recursion

This is kind of a brainteaser question, since the code works perfectly fine as-is, it just irritates my aesthetic sense ever so slightly. I'm turning to Stack Overflow because my own brain is failing me right now. Here's a snippet of code that looks up an address using the Google Maps JS API and places a marker on a map. However, someti...

MySQL Advanced Query Brainteaser

I've been asked to create a financial report, which needs to give a total commission rate between two dates for several 'referrers'. That's the easy part. The difficult part is that the commission rate varies depending not only on the referrer but also on the type of referral and also on the number of referrals of that type that have be...

Java collections brain teasers

Java collections are invaluable tool in exchanging data between database and service layer. We have various cases of a HashMap, ArrayList, a HashMap of arraylists etc. I'm looking for programming samples, that contain a lot of exercise from simple to complex to deal with collections. It need not have answers/sample codes, just a variety...

T-SQL query to flag repeat records

I have a table that will have 500,000+ records. Each record has a LineNumber field which is not unique and not part of the primary key. Each record has a CreatedOn field. I need to update all 500,000+ records to identify repeat records. A repeat records is defined by a record that has the same LineNumber within the last seven days of i...

C# /Linq Yet another Brain Teaser

Friends, there is yet another scenario to solve. I am working it out without applying Linq.But I hope it is good opportunity for me to learn Linq if you share your code in Linq. It is know as FLAMES F - Friend L - Lover A - Admirer M - Marry(Husband) E - Enemy S - Sister Problem description: Tw...

Using Static Constructor (Jon Skeet Brainteaser)

As a relative newbie I try to read as much as I can about a particular subject and test/write as much code as I can. I was looking at one of Jons Brainteasers (question #2) and my output was different than the answer. Which makes brings me here to ask if something has changed in recent versions and to see what output others are getti...

C++ brain teaser

I recently refactored code like this (MyClass to MyClassR). #include <iostream> class SomeMember { public: double m_value; SomeMember() : m_value(0) {} SomeMember(int a) : m_value(a) {} SomeMember(int a, int b) : m_value(static_cast<double>(a) / 3.14159 + static_cast<double>(b) / 2.71828) {} }; class MyClass ...

How to find a checksum of the same checksum? (job-interview question)

Devise a simple algorithm which creates a file which contains nothing but its own checksum. Let's say it is CRC-32, so this file must be 4 bytes long. ...

convert a number to the shortest possible character string while retaining uniqueness

I have a list of digits number, say "123456", and I need to map it to a string, any string. The only constraint on the map functions are: each list of digits number must map to a unique character string (this means the string can be arbitrarily long) character string can only contain 0-9, a-z, A-Z What map function would produce the ...

Looking for an algorithm that will show how to fit the most boxes in a container.

I've been interested in writing an application that will show how to fit boxes (of random dimensions) in a container so there is as little space as possible left. A real life example would be something that would tell you how to use the most space in a UPS truck. Does anyone know of a good place to start for something like this? Is th...

Why 10675199.02:48:05.4775807 TimeSpan Maximum for CompilationSection?

I was looking at the metadata for System.Web.Configuration.CompilationSection, and noticed the following attribute on the TimeSpan BatchTimeout property: [TimeSpanValidator(MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")] Could someone explain why this is the allowed max value? TimeSpan itself has an upper...

Algorithm for seating groups of people?

I'm interested in writing an application that can determine how to seat groups of 2-10 people at tables that can hold 10 people. There will probably be about 15 tables and 140 people total. I don't want to break up any of the groups of people. It seems like it might be a common problem and I was wondering if anyone had any suggestions...

Dynamic javascript select dropdown

This was interesting. In a select dropdown, trying not to use jQuery (with the exception of easing some of my pain on recreation), I ran into an issue that doesn't properly let any current browsers catch the proper selected option. Here is my code, for the page that recreates the issue (remember, no jQuery to necessarily solve issue, b...

Sorting algorithm problem.

Here's a brain teaser that's been on my mind for a few days. We have a sequence S of n elements. Each element is an integer in the range [0, n^2-1]. Describe a simple method for sorting S in O(n) time. Probably something obvious that I am just missing, but I'd appreciate any insight. ...

Interview question: the duck and the fox

Brainteaser i have been given while competing for C++ programmer vacancy. Assume there is the pond of perfect circle shape. Right in the center of this pond the duck sits on a water. And right at the coast the fox stays. Of course she cannot swim. The fox is constantly trying to chase and catch the duck so her primary objective is to st...