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 Shreshth_Srivastava/Question1/Test Cases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions Shreshth_Srivastava/Question1/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def two_sum(nums, target):
num_map = {}

for i, num in enumerate(nums):
complement = target - num
if complement in num_map:
return [num_map[complement], i]
num_map[num] = i

return []

if __name__ == "__main__":

n = int(input("Enter the number of elements: "))


nums = list(map(int, input("Enter the elements separated by space: ").split()))

if len(nums) != n:
print(f"Error: Expected {n} elements, but got {len(nums)}.")
exit()


target = int(input("Enter the target: "))


result = two_sum(nums, target)

if result:
print(f"Output: {result}")
else:
print("No valid pair found.")
21 changes: 21 additions & 0 deletions Shreshth_Srivastava/Question2/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1

a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b

return b


if __name__ == "__main__":
n = int(input("Enter n (0 <= n <= 30): "))

if 0 <= n <= 30:
result = fib(n)
print(f"F({n}) = {result}")
else:
print("Invalid input. n must be between 0 and 30.")
Binary file added Shreshth_Srivastava/Question2/testcases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.