Skip to content

Instantly share code, notes, and snippets.

@manwar
Created December 15, 2025 11:13
Show Gist options
  • Select an option

  • Save manwar/466b743872e0d1705a893f2a6f1ed5ea to your computer and use it in GitHub Desktop.

Select an option

Save manwar/466b743872e0d1705a893f2a6f1ed5ea to your computer and use it in GitHub Desktop.
The Weekly Challenge - 353

The Weekly Challenge - 353

Early Bird Club members ONLY

Task 1: Max Words

Submitted by: Mohammad Sajid Anwar

You are given an array of sentences.

Write a script to return the maximum number of words that appear in a single sentence.

Example 1

Input: @sentences = ("Hello world", "This is a test", "Perl is great")
Output: 4

Example 2

Input: @sentences = ("Single")
Output: 1

Example 3

Input: @sentences = ("Short", "This sentence has six words in total", "A B C", "Just four words here")
Output: 6

Example 4

Input: @sentences = ("One", "Two parts", "Three part phrase", "")
Output: 3

Example 5

Input: @sentences = ("The quick brown fox jumps over the lazy dog", "A", "She sells seashells by the seashore", "To be or not to be that is the question")
Output: 10

Task 2: Validate Coupon

Submitted by: Mohammad Sajid Anwar

You are given three arrays, @codes, @names and @status.

Write a script to validate codes in the given array.

A code is valid when the following conditions are true:
- codes[i] is non-empty and consists only of alphanumeric characters (a-z, A-Z, 0-9) and underscores (_).
- names[i] is one of the following four categories: "electronics", "grocery", "pharmacy", "restaurant".
- status[i] is true.

Return an array of the codes of all valid coupons, sorted first by their names in the order

Example 1

Input: @codes  = ("A123", "B_456", "C789", "D@1", "E123")
       @names  = ("electronics", "restaurant", "electronics", "pharmacy", "grocery")
       @status = ("true", "false", "true", "true", "true")
Output: ("A123", "C789", "E123")

Example 2

Input: @codes  = ("Z_9", "AB_12", "G01", "X99", "test")
       @names  = ("pharmacy", "electronics", "grocery", "electronics", "unknown")
       @status = ("true", "true", "false", "true", "true")
Output: ("AB_12", "X99", "Z_9")

Example 3

Input: @codes  = ("_123", "123", "", "Coupon_A", "Alpha")
       @names  = ("restaurant", "electronics", "electronics", "pharmacy", "grocery")
       @status = ("true", "true", "false", "true", "true")
Output: ("123", "Alpha", "Coupon_A", "_123")

Example 4

Input: @codes  = ("ITEM_1", "ITEM_2", "ITEM_3", "ITEM_4")
       @names  = ("electronics", "electronics", "grocery", "grocery")
       @status = ("true", "true", "true", "true")
Output: ("ITEM_1", "ITEM_2", "ITEM_3", "ITEM_4")

Example 5

Input: @codes  = ("CAFE_X", "ELEC_100", "FOOD_1", "DRUG_A", "ELEC_99")
       @names  = ("restaurant", "electronics", "grocery", "pharmacy", "electronics")
       @status = ("true", "true", "true", "true", "false")
Output: ("ELEC_100", "FOOD_1", "DRUG_A", "CAFE_X")


Last date to submit the solution 23:59 (UK Time) Sunday 28th December 2025.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment