I tested it with various lists, and I always get the correct result. Does anyone see a problem in the code?