Skip to content

Commit

Permalink
Merge pull request #449 from avnisinngh/five_add
Browse files Browse the repository at this point in the history
adding leetcode solutions
  • Loading branch information
PRIYESHSINGH24 authored Jan 21, 2025
2 parents 661b298 + 234729b commit 245d567
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.HashMap;

class Solution {
public int maxSubarrayLength(int[] nums, int k) {
HashMap<Integer, Integer> map = new HashMap<>();
int ans = 0;
for(int left = 0, right = 0; right < nums.length; right++) {
map.put(nums[right], map.getOrDefault(nums[right], 0) + 1);
while(map.get(nums[right]) > k && left >=0){
map.put(nums[left], map.get(nums[left]) - 1);
left++;
}
ans = Math.max(ans, right - left + 1);
}
return ans;
}
}
18 changes: 18 additions & 0 deletions LeetCode/713. Subarray Product Less Than K.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int numSubarrayProductLessThanK(int[] nums, int k) {
int product = 1;
int count = 0;
int left = 0, right = 0;
while(right < nums.length){
product *= nums[right];
while(product >= k && left <= right){
product /= nums[left++];
}
if(product < k){
count += right - left + 1;
}
right++;
}
return count;
}
}

0 comments on commit 245d567

Please sign in to comment.