Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added submissions/Question1/Screenshot (4).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions submissions/Question1/solution.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added submissions/Question2/Screenshot (5).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions submissions/Question2/solution2.py
Original file line number Diff line number Diff line change
@@ -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