From 63a23660da485adfb98175ed0784316dc05dec5f Mon Sep 17 00:00:00 2001 From: ankitakulkarnigit Date: Mon, 13 Oct 2025 14:37:12 -0700 Subject: [PATCH] Competative coding --- Problem1.java | 0 Problem1.py | 11 +++++++++++ README.md | 30 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) delete mode 100644 Problem1.java create mode 100644 Problem1.py diff --git a/Problem1.java b/Problem1.java deleted file mode 100644 index e69de29b..00000000 diff --git a/Problem1.py b/Problem1.py new file mode 100644 index 00000000..6f83f078 --- /dev/null +++ b/Problem1.py @@ -0,0 +1,11 @@ +// Time Complexity =O(n) +// Space Complexity = O(n) + +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + hashmap = {} + for i in range(len(nums)): + comp = target - nums[i] + if comp in hashmap.keys(): + return [i,hashmap[comp]] + hashmap[nums[i]] = i \ No newline at end of file diff --git a/README.md b/README.md index c87cd58c..6525fdcb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,33 @@ # Competitive-Coding-2 Please submit the interview problems posted in slack channel here. The problems and statements are intentionally not shown here so that students are not able to see them in advance + +Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. + +You may assume that each input would have exactly one solution, and you may not use the same element twice. + +You can return the answer in any order. + + + +Example 1: + +Input: nums = [2,7,11,15], target = 9 +Output: [0,1] +Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. +Example 2: + +Input: nums = [3,2,4], target = 6 +Output: [1,2] +Example 3: + +Input: nums = [3,3], target = 6 +Output: [0,1] + + +Constraints: + +2 <= nums.length <= 104 +-109 <= nums[i] <= 109 +-109 <= target <= 109 +Only one valid answer exists.