Skip to content

Dahhou ilyas #10058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 29, 2023
111 changes: 111 additions & 0 deletions dynamic_programming/wildcard_matching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"""
Author : ilyas dahhou
Date : Oct 7, 2023

Task:
Given an input string (s) and a pattern (p), implement wildcard
pattern matching with support for '?' and '*' where:

'?' matches any single character.
'*' matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).

Implementation notes:
implementation Dynamic Programming up bottom approach.

Runtime complexity:O(m * n)

The implementation was tested on the
leetcode: https://leetcode.com/problems/wildcard-matching/


wildcard matching
Dynamic Programming: top -> down.

"""
import datetime


class CustomTimeZone(datetime.tzinfo):
def utcoffset(self, dt):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: utcoffset. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function utcoffset

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: utcoffset. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function utcoffset

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: utcoffset. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function utcoffset

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: utcoffset. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function utcoffset

Please provide type hint for the parameter: dt

print(dt)
return datetime.timedelta(hours=1)

def dst(self, dt):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: dst. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function dst

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: dst. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function dst

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: dst. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function dst

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: dst. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function dst

Please provide type hint for the parameter: dt

print(dt)
return datetime.timedelta(0)

def tzname(self, dt):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: tzname. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function tzname

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: tzname. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function tzname

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: tzname. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function tzname

Please provide type hint for the parameter: dt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: tzname. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file dynamic_programming/wildcard_matching.py, please provide doctest for the function tzname

Please provide type hint for the parameter: dt

print(dt)
return "Custom Time Zone"


tz_maroc = CustomTimeZone()

now_maroc = datetime.datetime.now(tz=tz_maroc)


def is_match(string: str, pattern: str) -> bool:
"""
>>> is_match("aa", "a")
False

>>> is_match("abc", "abc")
True

>>> is_match("abc", "*c")
True

>>> is_match("abc", "a*")
True

>>> is_match("abc", "*a*")
True

>>> is_match("abc", "?b?")
True

>>> is_match("abc", "*?")
True

>>> is_match("abc", "a*d")
False

>>> is_match("abc", "a*c?")
False

>>> is_match("", "")
True

>>> is_match("a", "")
False

>>> is_match("", "*")
True

>>> is_match("abc", "*bc")
True

>>> is_match("abc", "a*bc")
True
"""
m, n = len(string), len(pattern)
dp = [[False] * (n + 1) for _ in range(m + 1)]

# Base case
dp[0][0] = True

# Fill in the first row
for j in range(1, n + 1):
if pattern[j - 1] == "*":
dp[0][j] = dp[0][j - 1]

# Fill in the rest of the DP table
for i in range(1, m + 1):
for j in range(1, n + 1):
if pattern[j - 1] == "?" or string[i - 1] == pattern[j - 1]:
dp[i][j] = dp[i - 1][j - 1]
elif pattern[j - 1] == "*":
dp[i][j] = dp[i - 1][j] or dp[i][j - 1]

return dp[m][n]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ imageio
keras
lxml
matplotlib
mypy
numpy
opencv-python
pandas
Expand All @@ -20,5 +21,6 @@ sympy
tensorflow ; python_version < '3.12'
texttable
tweepy
types-pytz
xgboost
yulewalker