Slack Assignment
Slack Assignment
if arr[mid] == target:
return mid
low = mid + 1
else:
high = mid - 1
return -1
def rotate_matrix_90(matrix):
merged_list = []
i=j=0
merged_list.append(list1[i])
i += 1
else:
merged_list.append(list2[j])
j += 1
merged_list.extend(list1[i:])
merged_list.extend(list2[j:])
return merged_list
@lru_cache(maxsize=None)
def fibonacci(n):
if n < 2:
return n
if response.status_code == 200:
data = response.json()
return {
"City": data["name"],
else:
# 7. Shape Class with Subclasses Circle and Square Implemen ng Their Area Methods
class Shape:
def area(self):
raise NotImplementedError("Subclass must implement area method")
class Circle(Shape):
self.radius = radius
def area(self):
class Square(Shape):
self.side = side
def area(self):
return self.side ** 2
class Node:
self.value = value
self.next = None
class SinglyLinkedList:
def __init__(self):
self.head = None
new_node = Node(value)
if not self.head:
self.head = new_node
return
current = self.head
while current.next:
current = current.next
current.next = new_node
def display(self):
current = self.head
while current:
current = current.next
print("None")
# Example usage:
if __name__ == "__main__":
# Binary search
# Rotate matrix
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
print(rotate_matrix_90(matrix))
# Check anagram
print(is_anagram("listen", "silent"))
# Fibonacci with caching
print(fibonacci(10))
# print(fetch_weather("your_api_key", "London"))
# Shape areas
circle = Circle(5)
square = Square(4)
print(circle.area())
print(square.area())
linked_list = SinglyLinkedList()
linked_list.append(1)
linked_list.append(2)
linked_list.append(3)
linked_list.display()