From a75e563923eb357f43d87ffb41f0b4a41c64d9bb Mon Sep 17 00:00:00 2001 From: swali-98 <125756506+swali-98@users.noreply.github.com> Date: Wed, 28 May 2025 15:39:10 +0530 Subject: [PATCH 1/6] Add files via upload --- twosum/Solution.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 twosum/Solution.java diff --git a/twosum/Solution.java b/twosum/Solution.java new file mode 100644 index 0000000..2969d8f --- /dev/null +++ b/twosum/Solution.java @@ -0,0 +1,19 @@ +class Solution { + public int[] twoSum(int[] nums, int target) { + int[] arr = new int[2]; + Map hash=new HashMap<>(); + + for(int i=0;i Date: Wed, 28 May 2025 18:26:59 +0530 Subject: [PATCH 2/6] added solution for best time to buy stock --- best-time-to-buy-stock/Solution.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 best-time-to-buy-stock/Solution.java diff --git a/best-time-to-buy-stock/Solution.java b/best-time-to-buy-stock/Solution.java new file mode 100644 index 0000000..a60e40a --- /dev/null +++ b/best-time-to-buy-stock/Solution.java @@ -0,0 +1,13 @@ +class Solution { + public int maxProfit(int[] prices) { + int max=0; + int minAmount=prices[0]; + + for(int i=1;i Date: Thu, 29 May 2025 23:23:43 +0530 Subject: [PATCH 3/6] added solution for contains duplicate --- contains duplicate/Solution.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 contains duplicate/Solution.java diff --git a/contains duplicate/Solution.java b/contains duplicate/Solution.java new file mode 100644 index 0000000..f11850f --- /dev/null +++ b/contains duplicate/Solution.java @@ -0,0 +1,13 @@ +class Solution { + public boolean containsDuplicate(int[] nums) { + Set hash = new HashSet<>(); + + for(int i =0;i Date: Thu, 29 May 2025 23:54:04 +0530 Subject: [PATCH 4/6] added solution for sum of integers --- sum of integers/Solution.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sum of integers/Solution.java diff --git a/sum of integers/Solution.java b/sum of integers/Solution.java new file mode 100644 index 0000000..07a30e7 --- /dev/null +++ b/sum of integers/Solution.java @@ -0,0 +1,19 @@ +class Solution { + public int getSum(int a, int b) { + int carry =(a&b)<<1; + + int sum=a^b; + int total = sum ^ carry; + + System.out.println(total); + + while(carry!=0){ + carry=(sum&carry)<<1; + sum=total; + total^=carry; + + } + + return total; + } +} \ No newline at end of file From 02a26b494a5c1bd453d2d31e60f5f1609e5e8735 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 May 2025 23:47:54 +0530 Subject: [PATCH 5/6] added solution for max subarray --- max subarray/Solution.java | 22 ++++++++++++++++++++++ product of array/Solution.java | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 max subarray/Solution.java create mode 100644 product of array/Solution.java diff --git a/max subarray/Solution.java b/max subarray/Solution.java new file mode 100644 index 0000000..bae330f --- /dev/null +++ b/max subarray/Solution.java @@ -0,0 +1,22 @@ +class Solution { + public int maxSubArray(int[] nums) { + int max=nums[0]; + int value=nums[0]; + for(int i=1;i=value){ + value=nums[i]; + max=Math.max(value,max); + continue; + } + } + else{ + value+=nums[i]; + max=Math.max(max,value); + } + + } + + return max; + } +} \ No newline at end of file diff --git a/product of array/Solution.java b/product of array/Solution.java new file mode 100644 index 0000000..f055007 --- /dev/null +++ b/product of array/Solution.java @@ -0,0 +1,23 @@ +class Solution { + public int[] productExceptSelf(int[] nums) { + int[] arr=new int[nums.length]; + int value=1; + int[] prod=new int[nums.length]; + for(int i=0;i0;i--){ + + prod[i]=arr[k]*j; + j=j*nums[i]; + k--; + } + prod[0]=j; + return prod; + } +} \ No newline at end of file From 31844dd69b990fcee6d50b9c9df2303ac059e103 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jun 2025 13:55:23 +0530 Subject: [PATCH 6/6] added solution for day8 and day9 --- .../Solution.java | 19 +++++++++++++++++++ max product subarray/Solution.java | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 Find min in rotated sorted array/Solution.java create mode 100644 max product subarray/Solution.java diff --git a/Find min in rotated sorted array/Solution.java b/Find min in rotated sorted array/Solution.java new file mode 100644 index 0000000..14df913 --- /dev/null +++ b/Find min in rotated sorted array/Solution.java @@ -0,0 +1,19 @@ +class Solution { + public int findMin(int[] nums) { + int start = 0; + int end =nums.length-1; + int mid=0; + while(start<=end){ + mid=start+(end-start)/2; + + if(nums[mid]>=nums[end]){ + start=mid+1; + } + else { + end=mid; + } + } + + return nums[mid]; + } +} \ No newline at end of file diff --git a/max product subarray/Solution.java b/max product subarray/Solution.java new file mode 100644 index 0000000..5bb417f --- /dev/null +++ b/max product subarray/Solution.java @@ -0,0 +1,17 @@ +class Solution { + public int maxProduct(int[] nums) { + int max=nums[0]; + int min=nums[0]; + int globalMax=nums[0]; + for (int i =1;i