Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 2260. GJam 2011 Africa Qual A: Maximum Loop Size

Created by Richard Zapor

This Challenge is derived from GJam 2011 Africa: Closing the Loop. Small Case Google Code Jam 2014 Kicks Off its Qualifier round April 11. GJam Registration. The Test Suite, at the bottom, contains a full GJam file input read, process, and Output example.

Create the maximum length Loop of alternating Segment types (0 or 1). Return Maximum Length. Segment connection Knots reduce the Length by 1, including the end to the start knot. If no valid loop can be created then return 0.

Input: M, 2xN matrix of [Lengths(1:N);Types(1:N)], Types are 0 or 1

Output: L, maximum Loop Length of valid alternating segment types

Example: M=[6 1 7 3;1 0 1 0], L=13

Additional GJam solutions can be found at Example GJam Matlab solutions. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.

Tags

Problem Group

Solution Statistics

17 correct solutions 4 incorrect solutions
Last solution submitted on Nov 06, 2014

Solution Comments