Task 1: Greater Character You are given an array of characters (a..z) and a target character. Write a script to find out the smallest character in the given array lexicographically greater than the target character. Example 1 Input: @array = qw/e m u g/, $target = 'b' Output: e Example 2 Input: @array = qw/d c e f/, $target = 'a' Output: c Example 3 Input: @array = qw/j a r/, $target = 'o' Output: r Example 4 Input: @array = qw/d c a f/, $target = 'a' Output: c Example 5 Input: @array = qw/t g a l/, $target = 'v' Output: v MY NOTES: pretty easy, although example 5 seems to imply that the spec should say, "... or the target if no character in the array is bigger than the target". So that's the basis on which I'm proceeding: Note that "an array of characters" is awfully like "a string + split", so let's do that. Can do it as a one-liner: perl -MList::Util=minstr -E '( $target, $str ) = @ARGV; $x = minstr( grep { $_ gt $target } split( //, $str ) ) // ($target); say $x' a dcef GUEST LANGUAGE: As a bonus, I also had a go at translating ch-1.pl into C and Pascal (look in the relevant direcories for those translations) Task 2: Array Degree You are given an array of 2 or more non-negative integers. Write a script to find out the smallest slice, i.e. contiguous subarray of the original array, having the degree of the given array. The degree of an array is the maximum frequency of an element in the array. Example 1 Input: @array = (1, 3, 3, 2) Output: (3, 3) The degree of the given array is 2. The possible subarrays having the degree 2 are as below: (3, 3) (1, 3, 3) (3, 3, 2) (1, 3, 3, 2) And the smallest of all is (3, 3). Example 2 Input: @array = (1, 2, 1, 3) Output: (1, 2, 1) Example 3 Input: @array = (1, 3, 2, 1, 2) Output: (2, 1, 2) Example 4 Input: @array = (1, 1, 2, 3, 2) Output: (1, 1) Example 5 Input: @array = (2, 1, 2, 1, 1) Output: (1, 2, 1, 1) MY NOTES: Ok, sounds pretty easy. Finding the degree of an array range involves building a frequency hash, the degree is max( values %freq ). Finding the smallest subarray is easier enough, although tedious. GUEST LANGUAGE: As a bonus, I also had a go at translating ch-2.pl into C and Pascal (look in the relevant direcories for those translations)