From d5ab1dda55fc2fadda95eec4d995c1c9d1182ce0 Mon Sep 17 00:00:00 2001 From: Dipanita45 <132455672+Dipanita45@users.noreply.github.com> Date: Mon, 14 Apr 2025 12:03:51 +0530 Subject: [PATCH 1/7] Add maximum value of Ordered Triplets --- Java/.project | 11 ++++++++ ...Maximum Value of an Ordered Triplets.java | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Java/Maximum Value of an Ordered Triplets.java diff --git a/Java/.project b/Java/.project index 4fdb69a93e..e4eed73892 100644 --- a/Java/.project +++ b/Java/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1744612223460 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Java/Maximum Value of an Ordered Triplets.java b/Java/Maximum Value of an Ordered Triplets.java new file mode 100644 index 0000000000..0d66520084 --- /dev/null +++ b/Java/Maximum Value of an Ordered Triplets.java @@ -0,0 +1,28 @@ + +class Solution { + public long maximumTripletValue(int[] nums){ + int n = nums.length; + if (n < 3) return 0; + + int[] leftMax = new int[n]; + leftMax[0] = nums[0]; + for (int i = 1; i < n; i++) { + leftMax[i] = Math.max(leftMax[i - 1], nums[i]); + } + + int[] rightMax = new int[n]; + rightMax[n - 1] = nums[n - 1]; + for (int i = n - 2; i >= 0; i--) { + rightMax[i] = Math.max(rightMax[i + 1], nums[i]); + } + + long ans = 0; + for (int i = 1; i < n - 1; i++) { + int left = leftMax[i - 1]; + int right = rightMax[i + 1]; + ans = Math.max(ans, (long)(left - nums[i]) * right); + } + + return ans; + } +} \ No newline at end of file From 797743ff1291441a8bd7c07c72ba619336e33b46 Mon Sep 17 00:00:00 2001 From: Dipanita45 <132455672+Dipanita45@users.noreply.github.com> Date: Mon, 14 Apr 2025 12:08:51 +0530 Subject: [PATCH 2/7] U --- Java/Maximum Value of an Ordered Triplets.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Java/Maximum Value of an Ordered Triplets.java b/Java/Maximum Value of an Ordered Triplets.java index 0d66520084..1453d1b089 100644 --- a/Java/Maximum Value of an Ordered Triplets.java +++ b/Java/Maximum Value of an Ordered Triplets.java @@ -1,3 +1,5 @@ + //TC:O(N) + //SC:O(N) class Solution { public long maximumTripletValue(int[] nums){ From 3cabcced8a53ab5de09d26c13d3b9f86afc26f53 Mon Sep 17 00:00:00 2001 From: Dipanita45 <132455672+Dipanita45@users.noreply.github.com> Date: Tue, 15 Apr 2025 10:43:30 +0530 Subject: [PATCH 3/7] Change --- C++/Combination Sum.cpp | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 C++/Combination Sum.cpp diff --git a/C++/Combination Sum.cpp b/C++/Combination Sum.cpp new file mode 100644 index 0000000000..6c9ffc221d --- /dev/null +++ b/C++/Combination Sum.cpp @@ -0,0 +1,49 @@ +#include +#include + +class Solution { + + public: + + vector> combinationSum(vector& candidates, int target) { + + vector> res; + + vector comb; + + makeCombination(candidates, target, 0, comb, 0, res); + + return res; + + } + + private: + + void makeCombination(std::vector& candidates, int target, int idx, vector& comb, int total, vector>& res) { + + if (total == target) { + + res.push_back(comb); + + return; + + } + + if (total > target || idx >= candidates.size()) { + + return; + + } + + comb.push_back(candidates[idx]); + + makeCombination(candidates, target, idx, comb, total + candidates[idx], res); + + comb.pop_back(); + + makeCombination(candidates, target, idx + 1, comb, total, res); + + } + + }; + \ No newline at end of file From 3c135ec3223ba13d545476793573536f56222e67 Mon Sep 17 00:00:00 2001 From: Dipanita45 <132455672+Dipanita45@users.noreply.github.com> Date: Wed, 16 Apr 2025 14:49:36 +0530 Subject: [PATCH 4/7] Create Count of Good Subarrays.java --- Java/Count of Good Subarray.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Java/Count of Good Subarray.java diff --git a/Java/Count of Good Subarray.java b/Java/Count of Good Subarray.java new file mode 100644 index 0000000000..da19d185c5 --- /dev/null +++ b/Java/Count of Good Subarray.java @@ -0,0 +1,22 @@ +public class Solution { + + public long countGood(int[] nums, int k) { + int n = nums.length; + int same = 0, right = -1; + HashMap cnt = new HashMap<>(); + long ans = 0; + for (int left = 0; left < n; ++left) { + while (same < k && right + 1 < n) { + ++right; + same += cnt.getOrDefault(nums[right], 0); + cnt.put(nums[right], cnt.getOrDefault(nums[right], 0) + 1); + } + if (same >= k) { + ans += n - right; + } + cnt.put(nums[left], cnt.get(nums[left]) - 1); + same -= cnt.get(nums[left]); + } + return ans; + } +} From 1aa98bec7600cb53e83dd12531056f97b96f1d17 Mon Sep 17 00:00:00 2001 From: Dipanita45 <132455672+Dipanita45@users.noreply.github.com> Date: Thu, 17 Apr 2025 09:37:57 +0530 Subject: [PATCH 5/7] Add Create Equal and Divisible in an Array --- Java/Count Equal and Divisible in an Array.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Java/Count Equal and Divisible in an Array.java diff --git a/Java/Count Equal and Divisible in an Array.java b/Java/Count Equal and Divisible in an Array.java new file mode 100644 index 0000000000..22d9f82330 --- /dev/null +++ b/Java/Count Equal and Divisible in an Array.java @@ -0,0 +1,17 @@ +class Solution { + public int countPairs(int[] nums, int k) { + int n=nums.length; + int res=0; + for(int i=0;i Date: Mon, 21 Apr 2025 20:31:48 +0530 Subject: [PATCH 6/7] Update --- Java/Count Hidden Sequence.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Java/Count Hidden Sequence.java diff --git a/Java/Count Hidden Sequence.java b/Java/Count Hidden Sequence.java new file mode 100644 index 0000000000..5dc354b7f9 --- /dev/null +++ b/Java/Count Hidden Sequence.java @@ -0,0 +1,18 @@ +public class Solution { + public int numberOfArrays(int[] differences, int lower, int upper) { + int n = differences.length; + int prefix = 0; + int min = 0; + int max = 0; + int diff = upper-lower; + for(int i = 0;i diff) return 0; + } + return (diff) - (max -min) +1; + } +} + + From 5e4c852cd8174e09303f46618889ab233231b656 Mon Sep 17 00:00:00 2001 From: Dipanita45 <132455672+Dipanita45@users.noreply.github.com> Date: Mon, 21 Apr 2025 20:32:58 +0530 Subject: [PATCH 7/7] u --- Java/Count Hidden Sequence.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Java/Count Hidden Sequence.java b/Java/Count Hidden Sequence.java index 5dc354b7f9..c398d16df7 100644 --- a/Java/Count Hidden Sequence.java +++ b/Java/Count Hidden Sequence.java @@ -1,10 +1,11 @@ -public class Solution { +public class Solution { public int numberOfArrays(int[] differences, int lower, int upper) { int n = differences.length; int prefix = 0; int min = 0; int max = 0; int diff = upper-lower; + for(int i = 0;i