Introduction

Hello there! In this unit, we're offering an engaging coding lesson that highlights the performance efficiencies provided by utilizing PHP's associative arrays. We'll address a list-based problem that requires us to make an optimal choice to minimize the size of our list. Excited? So am I! Let's get started.

Task Statement

In this unit's task, we'll manipulate an array of integers. You are required to construct a PHP function titled minimalMaxBlock(). This function should accept an array as input and compute an intriguing property related to contiguous blocks within the array.

More specifically, you must select a particular integer, $k, from the array. Once you've selected $k, the function should remove all occurrences of $k from the array, thereby splitting it into several contiguous blocks or remaining sub-arrays. A unique feature of $k is that it is chosen so that the maximum length among these blocks is minimized.

For instance, consider the array [1, 2, 2, 3, 1, 4, 4, 4, 1, 2, 5]. If we eliminate all instances of 2 (our $k), the remaining blocks would be [1], [3, 1, 4, 4, 4, 1], [5], with the longest containing 6 elements. Now, if we instead remove all instances of 1, the new remaining blocks would be , , , the longest of which contains 3 elements. As such, the function should return 1 in this case, as it leads to a minimally maximal block length.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal