From c8ad286ed717462f59ab04d6af78cabce28c1285 Mon Sep 17 00:00:00 2001 From: kalyan Date: Mon, 13 Oct 2025 14:59:37 -0500 Subject: [PATCH] Competitive-Coding-2 solutions --- Problem1.java | 22 ++++++++++++++++++++++ Problem2.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Problem1.java b/Problem1.java index e69de29b..8a9c8f14 100644 --- a/Problem1.java +++ b/Problem1.java @@ -0,0 +1,22 @@ +//Two Sum problem +// Time Complexity : O(n). +// Space Complexity : O(n) +// Did this code successfully run on Leetcode : Yes +// Approach : As we have to check if the target can be achieved with addition of two numbers in the Array, I have calculated the difference by subtracting +// target and nums[i]. Then we check in the HashMap if the differnce is present, if not we add to the HashMap. + + +class Solution { + public int[] twoSum(int[] nums, int target) { + HashMap map = new HashMap<>(); + for(int i=0; i