diff --git a/Shreshth_Srivastava/Question1/Test Cases.png b/Shreshth_Srivastava/Question1/Test Cases.png new file mode 100644 index 0000000..d85e51d Binary files /dev/null and b/Shreshth_Srivastava/Question1/Test Cases.png differ diff --git a/Shreshth_Srivastava/Question1/solution.py b/Shreshth_Srivastava/Question1/solution.py new file mode 100644 index 0000000..f01b5c6 --- /dev/null +++ b/Shreshth_Srivastava/Question1/solution.py @@ -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.") diff --git a/Shreshth_Srivastava/Question2/solution.py b/Shreshth_Srivastava/Question2/solution.py new file mode 100644 index 0000000..1a91533 --- /dev/null +++ b/Shreshth_Srivastava/Question2/solution.py @@ -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.") diff --git a/Shreshth_Srivastava/Question2/testcases.png b/Shreshth_Srivastava/Question2/testcases.png new file mode 100644 index 0000000..8d8fff8 Binary files /dev/null and b/Shreshth_Srivastava/Question2/testcases.png differ