diff --git a/submissions/Question1/Screenshot (4).png b/submissions/Question1/Screenshot (4).png new file mode 100644 index 0000000..c2969c7 Binary files /dev/null and b/submissions/Question1/Screenshot (4).png differ diff --git a/submissions/Question1/solution.py b/submissions/Question1/solution.py new file mode 100644 index 0000000..a81b0bc --- /dev/null +++ b/submissions/Question1/solution.py @@ -0,0 +1,17 @@ +class Solution: + def longestCommonPrefix(self, strs): + if not strs: + return "" + + # Start with the first string as prefix + prefix = strs[0] + + # Compare with each string + for s in strs[1:]: + # Reduce the prefix until it matches the start of s + while not s.startswith(prefix): + prefix = prefix[:-1] + if not prefix: + return "" + + return prefix diff --git a/submissions/Question2/Screenshot (5).png b/submissions/Question2/Screenshot (5).png new file mode 100644 index 0000000..8715cdf Binary files /dev/null and b/submissions/Question2/Screenshot (5).png differ diff --git a/submissions/Question2/solution2.py b/submissions/Question2/solution2.py new file mode 100644 index 0000000..2260e02 --- /dev/null +++ b/submissions/Question2/solution2.py @@ -0,0 +1,20 @@ +class Solution: + def validPalindrome(self, s): + def is_palindrome(left, right): + while left < right: + if s[left] != s[right]: + return False + left += 1 + right -= 1 + return True + + left, right = 0, len(s) - 1 + + while left < right: + if s[left] != s[right]: + # Try deleting one character either from left or right + return is_palindrome(left + 1, right) or is_palindrome(left, right - 1) + left += 1 + right -= 1 + + return True