Skip to content

Instantly share code, notes, and snippets.

@manwar
Last active November 2, 2025 13:41
Show Gist options
  • Select an option

  • Save manwar/3e2187c2210cc9a44c89ae99a9cc6233 to your computer and use it in GitHub Desktop.

Select an option

Save manwar/3e2187c2210cc9a44c89ae99a9cc6233 to your computer and use it in GitHub Desktop.
The Weekly Challenge - 346

The Weekly Challenge - 346

Early Bird Club members ONLY

Task 1: Longest Parenthesis

Submitted by: Mohammad Sajid Anwar

You are given a string containing only ( and ).

Write a script to find the length of the longest valid parenthesis.


Example 1

Input: $str = '(()())'
Output: 6

Valid Parenthesis: '(()())'

Example 2

Input: $str = ')()())'
Output: 4

Valid Parenthesis: '()()' at positions 1-4.

Example 3

Input: $str = '((()))()(((()'
Output: 8

Valid Parenthesis: '((()))()' at positions 0-7.

Example 4

Input: $str = '))))((()('
Output: 2

Valid Parenthesis: '()' at positions 6-7.

Example 5

Input: $str = '()(()'
Output: 2

Valid Parenthesis: '()' at positions 0-1 and 3-4.

Task 2: Magic Expression

Submitted by: Mohammad Sajid Anwar

You are given a string containing only digits and a target integer.

Write a script to insert binary operators +, - and * between the digits in the given string that evaluates to target integer. Numbers with leading zeroes are invalid and the results should be in lexicographic order.


Example 1

Input: $str = "123", $target = 6
Output: ("1*2*3", "1+2+3")

Example 2

Input: $str = "105", $target = 5
Output: ("1*0+5", "10-5")

Example 3

Input: $str = "232", $target = 8
Output: ("2*3+2", "2+3*2")

Example 4

Input: $str = "1234", $target = 10
Output: ("1*2*3+4", "1+2+3+4")

Example 5

Input: $str = "1001", $target = 2
Output: ("1+0*0+1", "1+0+0+1", "1+0-0+1", "1-0*0+1", "1-0+0+1", "1-0-0+1")


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


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