Posts

Showing posts from December, 2024

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #298 ("Maximal Squares" and "Right Intervals")

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-12-01 through 2024-12-07 is #298. The tasks for challenge #298 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 298-1: Maximal Square Submitted by: Mohammad Sajid Anwar You are given an m x n binary matrix with 0 and 1 only. Write a script to find the largest square containing only 1's and return it’s area. Example #1: Input: @matrix = [1, 0, 1, 0, 0] [1, 0, 1, 1, 1] [1, 1, 1, 1, 1] [1, 0, 0, 1, 0] Output: 4 Two maximal square found with same size marked as 'x': [1, 0, 1, 0, 0] [1, 0, x, x, 1] [1, 1, x, x, 1] [1, 0, 0, 1, 0] [1, 0, 1, 0, 0] [1, 0, 1, x, x] [1, 1, 1, x, x] [1, 0, 0, 1, 0] Example #2: Input: @matrix = [0, 1] [1, 0] Output: 1 Two maximal square found with same size marked as 'x': [0, x] [...