The Weekly Challenge

The Weekly Challenge, run by Mohammad Sajid Manwar (https://theweeklychallenge.org/), offers a fun set of programming puzzles. I work through them in Perl. Some are pretty challenging, others are nice and simple.

Below is a selection of solutions to problems I quickly wrapped my head around and that have short, straightforward implementations. Hopefully, they'll be useful - or at least interesting - on your Perl journey.

The table below shows the challenge number (with a link), a short description of the challenge, and the most important keywords referring to L1–L3 classification system:

L1 (Type) – What kind of problem it is Examples: string parsing, sorting, frequency, arrays

L2 (Technique) – How it is solved Examples: hashing, sorting, regex, iteration, split/join

L3 (Pattern) – Specific trick or idea used Examples: frequency sorting, digit splitting, cumulative sums

Problem Table (L1–L2–L3 Filterable)
ID Description Tags
String Parsing & Manipulation
364-2 Interpret the given string using Goal Parser. L1: string_parsing | L2: regex
358-1 Find the maximum alphanumeric value. L1: string_parsing | L2: regex
340-1 Remove adjacent duplicate letters repeatedly. L1: string_manipulation | L2: regex | L3: adjacent_removal_loop
319-1 Count words starting or ending with a vowel. L1: string_parsing | L2: regex | L3: filtering
301-1 Arrange integers into largest concatenated number. L1: sorting_selection | L2: sorting | L3: custom_comparator
229-1 Delete unsorted elements and return deletion count. L1: sorting_selection | L2: sorting
233-2 Sort by increasing frequency, decreasing value on ties. L1: frequency_analysis | L2: hash_map + sorting | L3: frequency_sort
238-1 Return cumulative sums of array elements. L1: sequence_transformation | L2: iteration | L3: cumulative_sum
255-1 Find additional character between strings. L1: string_manipulation | L2: split_join_map
190-1 Check whether capitalization usage is correct. L1: string_parsing | L2: regex
Frequency & Hash-Based Analysis
375-1 Return the number of strings that appear exactly once in
each of two arrays.
L1: frequency_analysis | L2: hash_map | L3: unique_intersection_count
032-1 Count instances and print a summary sorted by frequency. L1: frequency_analysis | L2: hash_map | L3: frequency_sort
289-1 Third distinct maximum number. L1: sorting_selection | L2: sorting
219-1 Square numbers and return sorted results ascending. L1: frequency_analysis | L2: hash_map + sorting
225-1 Find the maximum occurrence count of elements. L1: frequency_analysis | L2: iteration
221-1 Sum lengths of words constructible from given characters. L1: frequency_analysis | L2: hash_map
240-1 Check whether string matches words' acronym. L1: string_parsing | L2: iteration
Split / Join / Transformations
375-2 Count substrings of length k (from the number as a string)
whose numeric value is a divisor of the given number.
L1: number_theory | L2: substring_analysis | L3: divisibility_check
365-1 Convert letters to digits, repeatedly sum digits k times. L1: sequence_transformation | L2: split_join_map | L3: digit_decomposition
363-1 Self-referential string parser. L1: string_parsing | L2: split_join_map | L3: hash_state_machine
278-1 Reassemble shuffled sentence. L1: sequence_transformation | L2: split_join_map + sorting
208-1 Find common strings with minimum index sum. L1: sequence_transformation | L2: iteration
254-1 Check whether integer is a power of three. L1: math_logical | L2: numeric_computation
254-2 Process strings using positional replacement rules. L1: sequence_transformation | L2: split_join_map
Sorting / Ordering & Selection
362-2 Alphabetical order of integers. L1: sorting_selection | L2: sorting | L3: schwartzian_transform
228-2 Count rotations/removals needed to delete all elements in
sorted order.
L1: sorting_selection | L2: simulation
213-1 Sort even numbers first, then odd numbers, both ascending. L1: sorting_selection | L2: sorting
218-1 Find three integers producing the maximum possible product. L1: sorting_selection | L2: sorting
222-1 Sort integers and count total matching members. L1: sorting_selection | L2: sorting
231-1 Return elements excluding minimum and maximum; else -1 if none. L1: sorting_selection | L2: sorting
Array & Sequence Processing
186-1 Merge two lists in alternating order. L1: sequence_transformation | L2: iteration
230-1 Split each number into individual digits, flatten into array. L1: sequence_transformation | L2: split_join_map | L3: digit_decomposition
256-2 Merge strings alternately, appending leftovers from longer string. L1: sequence_transformation | L2: iteration
Substring & Character Manipulation
173-1 Determine whether a number is an Esthetic Number. L1: string_manipulation | L2: split_join_map | L3: abs_diff_check
180-1 Find the first unique character and return its index. L1: string_manipulation | L2: hash_map
184-1 Replace the first two characters using incrementing numeric prefixes. L1: string_manipulation | L2: substr
215-1 Count and remove words whose letters aren’t alphabetically ordered. L1: string_parsing | L2: iteration + regex
229-2 Return elements appearing in at least two of three arrays. L1: frequency_analysis | L2: hash_map