question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
single-element-in-a-sorted-array | easy c++ solution using binary search || self explanatory code | easy-c-solution-using-binary-search-self-6hib | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Rhythm_1383 | NORMAL | 2023-08-15T10:17:07.694251+00:00 | 2023-08-15T10:17:07.694270+00:00 | 326 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 4 | 0 | ['C++'] | 0 |
single-element-in-a-sorted-array | Very Simple (Easy to Understand) 0ms , c++ soln | very-simple-easy-to-understand-0ms-c-sol-0ywv | \n\n# Approach\n\n Let There be 2 arrays .\n a1 = [1,1,2,2,3,3,4,4]; -> point 1\n a2 = [1,1,2,2,3,3]; -> point 2\n\n here , let start = 0 , end = a | gowrijaswanth3 | NORMAL | 2023-05-13T00:07:18.143856+00:00 | 2023-05-14T08:25:08.867404+00:00 | 206 | false | \n\n# Approach\n\n Let There be 2 arrays .\n a1 = [1,1,2,2,3,3,4,4]; -> point 1\n a2 = [1,1,2,2,3,3]; -> point 2\n\n here , let start = 0 , end = arr.size() -1;\n\n a1 has even no of pairs = 4 , s = 0 , e = 7;\n a2 has odd no of pairs = 3 , s = 0, e = 5;\n\n Let us assume 1 element added to the ... | 4 | 0 | ['C++'] | 1 |
single-element-in-a-sorted-array | Easy 5 line Solution JAVA 100 % beats 0ms | easy-5-line-solution-java-100-beats-0ms-7kpjg | Intuition\nonly odd number of elements will contain 1 non duplicate elment\n# Approach\nmove towards the segment which has odd number of elements \n\n//checking | rajAbhinav | NORMAL | 2023-04-12T08:37:00.095914+00:00 | 2023-04-12T08:37:00.095955+00:00 | 520 | false | # Intuition\nonly odd number of elements will contain 1 non duplicate elment\n# Approach\nmove towards the segment which has odd number of elements \n```\n//checking for odd sequence\n if((high+1-mid)%2!=0) return solve(low,mid,nums);\n//checking for odd sequence\n if((high+1-mid+1)%2!=0) return solve(mi... | 4 | 0 | ['Binary Search', 'Java'] | 0 |
single-element-in-a-sorted-array | 540: Time 93.53%, Solution with step by step explanation | 540-time-9353-solution-with-step-by-step-a13z | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n- Initialize two pointers left and right to point to the first and last e | Marlen09 | NORMAL | 2023-03-14T05:00:53.868321+00:00 | 2023-03-14T05:00:53.868357+00:00 | 234 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- Initialize two pointers left and right to point to the first and last element of the array respectively.\n- Implement binary search until left and right point to the same element.\n- Compute the mid index as the average of... | 4 | 0 | ['Array', 'Binary Search', 'Python', 'Python3'] | 0 |
single-element-in-a-sorted-array | Beats 91.47%||C++||Binary Search||Easy | beats-9147cbinary-searcheasy-by-heisenbe-wmnb | Complexity\n- Time complexity:\nO(logn)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n//index of form:(even,odd) before pivot and of form | Heisenberg2003 | NORMAL | 2023-02-21T12:16:22.807614+00:00 | 2023-02-21T12:16:22.807647+00:00 | 358 | false | # Complexity\n- Time complexity:\nO(logn)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n//index of form:(even,odd) before pivot and of form (odd,even) after pivot for equal elements\n int singleNonDuplicate(vector<int>&nums) \n {\n int left=0,right=nums.size()-1;\n while(le... | 4 | 0 | ['C++'] | 0 |
single-element-in-a-sorted-array | Best C++✅Solution💥||Beats 87%🔥||Intuition Explained✅||O(logn)TC||O(1) SC | best-csolutionbeats-87intuition-explaine-5gx7 | Follow Daily Dose of DSA Blog where I post important DSA Questions and different approaches for solving it!!!\nhttps://legolas12.hashnode.dev/\n\n\n# Intuition | legolas12 | NORMAL | 2023-02-21T10:59:39.188083+00:00 | 2023-02-21T12:01:40.075069+00:00 | 799 | false | Follow Daily Dose of DSA Blog where I post important DSA Questions and different approaches for solving it!!!\nhttps://legolas12.hashnode.dev/\n) Space complexity: O(1) | busigor | NORMAL | 2023-02-21T05:21:06.426251+00:00 | 2023-02-21T05:21:06.426302+00:00 | 1,535 | false | # Approach\nPosition of the searched element is always even. We can find the position by using binary search.\n\nTime complexity: $$O(log(n))$$ Space complexity: $$O(1)$$\n\n# Code\n```\npublic class Solution {\n public int SingleNonDuplicate(int[] nums) {\n int l = 0, r = nums.Length / 2;\n while (l <... | 4 | 0 | ['C#'] | 3 |
single-element-in-a-sorted-array | Binary Search Easy Left and Right Half Approach | binary-search-easy-left-and-right-half-a-obcl | Intuition\ncheck for left half and right half\n\n# Approach\nobservation->in left half odd index->2nd occurance of some no\neven index->1st occurance of no\nin | sumitpadadune1689 | NORMAL | 2023-02-21T04:43:27.027159+00:00 | 2023-02-21T04:45:20.067828+00:00 | 698 | false | # Intuition\ncheck for left half and right half\n\n# Approach\nobservation->in left half odd index->2nd occurance of some no\neven index->1st occurance of no\nin right half\nodd index ->first occurance of no\neven index->second occurance\naccording reduce search space by applying mid+1 or mid-1 for \nperticular conditi... | 4 | 0 | ['C++'] | 0 |
single-element-in-a-sorted-array | C# Binary Search Explained | c-binary-search-explained-by-lavinamall-lxbn | Approach\n1. if there\'s only one element return it\n2. check if the unique element is the first or last element of the array\n\nCASE 1: element at mid and mid | lavinamall | NORMAL | 2023-02-21T03:33:47.264498+00:00 | 2023-02-21T03:33:47.264546+00:00 | 288 | false | # Approach\n1. if there\'s only one element return it\n2. check if the unique element is the first or last element of the array\n\n**CASE 1**: element at mid and mid - 1 are equal; \n - get count of left array and check if it is even or odd\n - in case it is even, discard and search **right**\n - in case of od... | 4 | 0 | ['Binary Search', 'C#'] | 1 |
single-element-in-a-sorted-array | Python short and clean. Binary Search. | python-short-and-clean-binary-search-by-r64hw | Approach\n1. Since nums is sorted and it is guaranteed that all but one number occurs exactly twice. We can binary search for the number with no pair.\n\n2. Say | darshan-as | NORMAL | 2023-02-21T03:26:12.690876+00:00 | 2023-02-21T18:09:18.941018+00:00 | 118 | false | # Approach\n1. Since `nums` is sorted and it is guaranteed that all but one number occurs exactly twice. We can binary search for the number with no pair.\n\n2. Say `m` is the mid point in the search and if all numbers had pairs,\n If `m` is even index, the repeating pair should be at `m + 1`.\n If `m` is odd ind... | 4 | 0 | ['Array', 'Math', 'Python', 'Python3'] | 0 |
single-element-in-a-sorted-array | ✅Python || 💥C++ ||✔ Clean and Concise Solution💥||🚀 O(logN) Binary Search | python-c-clean-and-concise-solution-olog-aij3 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | santhosh1608 | NORMAL | 2023-02-21T02:23:47.779811+00:00 | 2023-02-21T02:23:47.779848+00:00 | 395 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(log n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g.... | 4 | 0 | ['Array', 'Binary Search', 'Python'] | 0 |
single-element-in-a-sorted-array | Swift | Binary Search | 6 SLOC | swift-binary-search-6-sloc-by-upvotethis-znws | \u26A0\uFE0F - Solution is supposed to be O(log n)/O(1). Seeing many Swift posted solutions that are O(n)/O(n).\n\n---\nBinary Search (accepted answer)\n\nclass | UpvoteThisPls | NORMAL | 2023-02-21T00:23:05.417067+00:00 | 2023-02-21T02:54:43.272461+00:00 | 985 | false | \u26A0\uFE0F - Solution is supposed to be O(log n)/O(1). Seeing many Swift posted solutions that are O(n)/O(n).\n\n---\n**Binary Search (accepted answer)**\n```\nclass Solution {\n func singleNonDuplicate(_ nums: [Int]) -> Int {\n var (left, right) = (0, nums.count-1)\n while left < right {\n ... | 4 | 0 | ['Swift'] | 0 |
single-element-in-a-sorted-array | 🗓️ Daily LeetCoding Challenge February, Day 21 | daily-leetcoding-challenge-february-day-w19rn | This problem is the Daily LeetCoding Challenge for February, Day 21. Feel free to share anything related to this problem here! You can ask questions, discuss wh | leetcode | OFFICIAL | 2023-02-21T00:00:16.174853+00:00 | 2023-02-21T00:00:16.174921+00:00 | 11,315 | false | This problem is the Daily LeetCoding Challenge for February, Day 21.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please ... | 4 | 0 | [] | 36 |
single-element-in-a-sorted-array | Simple C++ code in log(n) complexity | simple-c-code-in-logn-complexity-by-vish-4d06 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | vishu_0123 | NORMAL | 2023-02-11T13:24:17.327520+00:00 | 2023-02-11T13:24:17.327552+00:00 | 864 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 4 | 0 | ['C++'] | 0 |
single-element-in-a-sorted-array | Best O(LogN) Solution | best-ologn-solution-by-kumar21ayush03-xupt | Approach 1\nXOR\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n int singleNonDuplicate(vector | kumar21ayush03 | NORMAL | 2023-01-26T15:04:50.837749+00:00 | 2023-01-26T15:04:50.837795+00:00 | 353 | false | # Approach 1\nXOR\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n int ans = 0;\n for (int i = 0; i < nums.size(); i++)\n ans = ans ^ nums[i];\n return ans; \n }\... | 4 | 0 | ['C++'] | 0 |
number-of-subarrays-with-bounded-maximum | Python , standard DP solution with explanation | python-standard-dp-solution-with-explana-nddk | Suppose dp[i] denotes the max number of valid sub-array ending with A[i]. We use following example to illustrate the idea: A = [2, 1, 4, 2, 3], L = 2, R = 3 if | charleszhou327 | NORMAL | 2018-03-04T17:49:28.590992+00:00 | 2018-10-18T05:29:20.324187+00:00 | 15,306 | false | Suppose __dp[i]__ denotes the max number of valid sub-array ending with __A[i]__. We use following example to illustrate the idea:
_A = [2, 1, 4, 2, 3], L = 2, R = 3_
1. if A[i] < L
For example, i = 1. We can only append A[i] to a valid sub-array ending with A[i-1] to create new sub-array. So we have __dp[i]... | 314 | 1 | [] | 24 |
number-of-subarrays-with-bounded-maximum | C++, O(n), <10 lines | c-on-10-lines-by-johnsontau-khxn | class Solution { public: int numSubarrayBoundedMax(vector<int>& A, int L, int R) { int result=0, left=-1, right=-1; for (int i=0; i<A.size() | johnsontau | NORMAL | 2018-03-04T04:46:14.582871+00:00 | 2018-10-24T20:15:35.083669+00:00 | 12,037 | false | ```
class Solution {
public:
int numSubarrayBoundedMax(vector<int>& A, int L, int R) {
int result=0, left=-1, right=-1;
for (int i=0; i<A.size(); i++) {
if (A[i]>R) left=i;
if (A[i]>=L) right=i;
result+=right-left;
}
return result;
}
};
``` | 241 | 4 | [] | 18 |
number-of-subarrays-with-bounded-maximum | [C++/Java/Python] Easy to understand solution - Clean & Concise - O(N) | cjavapython-easy-to-understand-solution-twkq3 | Idea\n- Let count(bound) is the number of subarrays which have all elements less than or equal to bound.\n- Finally, count(right) - count(left-1) is our result. | hiepit | NORMAL | 2021-06-17T10:58:05.384125+00:00 | 2021-06-17T17:10:01.087574+00:00 | 9,268 | false | **Idea**\n- Let `count(bound)` is the number of subarrays which have all elements less than or equal to `bound`.\n- Finally, `count(right) - count(left-1)` is our result.\n- How to compute `count(bound)`?\n\t- Let `ans` is our answer\n\t- Let `cnt` is the number of consecutive elements less than or equal to `bound` so ... | 207 | 16 | [] | 16 |
number-of-subarrays-with-bounded-maximum | JS, Python, Java, C++ | Easy Triangular Number Solution w/ Explanation | js-python-java-c-easy-triangular-number-sciyf | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-06-17T08:06:32.751788+00:00 | 2021-06-17T09:24:43.005862+00:00 | 5,027 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nThe key to this problem is realizing that we\'re dealing with overlapping **triangular number** issues. Importantly, the total number of possi... | 144 | 36 | ['C', 'Python', 'Java', 'JavaScript'] | 10 |
number-of-subarrays-with-bounded-maximum | Short Java O(n) Solution | short-java-on-solution-by-kay_deep-fmfi | ``` class Solution { public int numSubarrayBoundedMax(int[] A, int L, int R) { int j=0,count=0,res=0; for(int i=0;i<A.length;i++){ if(A[ | kay_deep | NORMAL | 2018-03-04T04:11:25.036176+00:00 | 2018-10-20T22:21:12.328395+00:00 | 14,099 | false | ```
class Solution {
public int numSubarrayBoundedMax(int[] A, int L, int R) {
int j=0,count=0,res=0;
for(int i=0;i<A.length;i++){
if(A[i]>=L && A[i]<=R){
res+=i-j+1;count=i-j+1;
}
else if(A[i]<L){
res+=count;
}... | 106 | 4 | [] | 15 |
number-of-subarrays-with-bounded-maximum | Number of Subarrays with Bounded Maximum | JS, Python, Java, C++ | Easy Triang. Number Sol. w/ Expl. | number-of-subarrays-with-bounded-maximum-42m1 | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-06-17T08:07:32.730295+00:00 | 2021-06-17T09:24:49.879118+00:00 | 2,572 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nThe key to this problem is realizing that we\'re dealing with overlapping **triangular number** issues. Importantly, the total number of possi... | 73 | 8 | [] | 4 |
number-of-subarrays-with-bounded-maximum | Java Explained Solution || O(1) Space || 2 Pointers || Similar Question | java-explained-solution-o1-space-2-point-yuzd | There are 3 Possible Cases :\n1. A[i] is between L and R (inclusive)\n2. A[i] is less than L\n3. A[i] is greater than R\n\nCASE 1: L<=A[i]<=R\nIt means that I( | himanshuchhikara | NORMAL | 2021-03-19T13:34:40.514198+00:00 | 2021-03-19T13:34:40.514227+00:00 | 3,283 | false | There are 3 Possible Cases :\n1. A[i] is between L and R (inclusive)\n2. A[i] is less than L\n3. A[i] is greater than R\n\n**CASE 1: L<=A[i]<=R**\n*It means that I(current element) can be part of previous subarrays (i-j) and also Can start a subarray from me (+1)\nSo add (i-j+1) in total Subarrays*\n\n**CASE 2: A[i]<L... | 61 | 0 | ['Two Pointers', 'Java'] | 6 |
number-of-subarrays-with-bounded-maximum | Clean & simple O(n) Java | clean-simple-on-java-by-octavila-7ss2 | \n public int numSubarrayBoundedMax(int[] A, int L, int R) {\n int start = -1, last = -1, res = 0;\n for(int i = 0; i < A.length; i++) {\n | octavila | NORMAL | 2018-03-14T03:18:15.666427+00:00 | 2018-10-24T06:47:28.404868+00:00 | 3,958 | false | ```\n public int numSubarrayBoundedMax(int[] A, int L, int R) {\n int start = -1, last = -1, res = 0;\n for(int i = 0; i < A.length; i++) {\n if(A[i] > R) {\n start = last = i;\n continue;\n }\n \n if(A[i] >= L)\n l... | 58 | 1 | [] | 5 |
number-of-subarrays-with-bounded-maximum | C++ O(n) solution with explanations | c-on-solution-with-explanations-by-nicky-q8xu | The idea is to keep track of 3 things while iterating: the number of valid subarrays (res), the number of valid subarray starting points (heads), and the number | nickyh | NORMAL | 2018-03-04T04:39:55.519776+00:00 | 2018-10-13T11:00:39.408351+00:00 | 5,152 | false | The idea is to keep track of 3 things while iterating: the number of valid subarrays (`res`), the number of valid subarray starting points (`heads`), and the number of not-yet valid starting points (`tails`).
* Values between `L` and `R` are heads. Every contiguous value afterwards that is less than R afterwards can e... | 50 | 2 | [] | 6 |
number-of-subarrays-with-bounded-maximum | a few solutions | a-few-solutions-by-claytonjwong-8f88 | There are 3 buckets which numbers in can be placed into:\n\n1) less than L\n2) less than or equal to R\n3) greater than R\n\nBucket 1 is a subset of Bucket 2. | claytonjwong | NORMAL | 2018-03-05T00:02:04.721767+00:00 | 2021-06-18T03:15:34.341432+00:00 | 2,129 | false | There are 3 buckets which numbers in can be placed into:\n\n1) less than `L`\n2) less than or equal to `R`\n3) greater than `R`\n\nBucket 1 is a subset of Bucket 2. Return the ongoing count of bucket 2 numbers minus the ongoing count of bucket 1 numbers. Completely ignore bucket 3. The ongoing count of bucket 1 and ... | 39 | 0 | [] | 1 |
number-of-subarrays-with-bounded-maximum | [Python] simple O(n) solution, explained | python-simple-on-solution-explained-by-d-lgfq | Let us iterate through numbers and keep index of last number which is >= L and index of last number, which is > R. Then, we can quickly calculate number of suba | dbabichev | NORMAL | 2021-06-17T10:11:03.722452+00:00 | 2021-06-17T11:06:24.673783+00:00 | 1,664 | false | Let us iterate through numbers and keep index of last number which is `>= L` and index of last number, which is `> R`. Then, we can quickly calculate number of subarrays with bounded maximum which ends on symbol with index `i`: in our window at least one number `>= L`, no numbers `> R`, so we calculate`L_ind - R_ind`. ... | 38 | 3 | [] | 4 |
number-of-subarrays-with-bounded-maximum | C++ Simple and Easy Explained Solution | c-simple-and-easy-explained-solution-by-dodmi | Brief Explanation:\nThere are three cases:\n1. The current number is greater than right - there are no new subarrays to add to res. We just update prev_bigger_t | yehudisk | NORMAL | 2021-06-17T08:38:18.359458+00:00 | 2021-06-17T09:02:35.832478+00:00 | 2,394 | false | **Brief Explanation:**\nThere are three cases:\n1. The current number is greater than right - there are no new subarrays to add to res. We just update prev_bigger_than_r = current index.\n2. The current number is smaller than left - we can add the new number to all valid previous subarrays which end here so far. But th... | 32 | 1 | ['C'] | 3 |
number-of-subarrays-with-bounded-maximum | Python Easy and Concise, one-pass O(N) time O(1) space, with Detailed Explanation | python-easy-and-concise-one-pass-on-time-eobv | py\nclass Solution(object):\n\tdef numSubarrayBoundedMax(self, A, L, R):\n\t\t"""\n\t\t:type A: List[int]\n\t\t:type L: int\n\t\t:type R: int\n\t\t:rtype: int\n | jianhaoz | NORMAL | 2019-01-25T03:24:11.493846+00:00 | 2019-01-25T03:24:11.493965+00:00 | 1,475 | false | ```py\nclass Solution(object):\n\tdef numSubarrayBoundedMax(self, A, L, R):\n\t\t"""\n\t\t:type A: List[int]\n\t\t:type L: int\n\t\t:type R: int\n\t\t:rtype: int\n\t\t"""\n\t\t# spec:\n\t\t# Return the number of (contiguous, non-empty) subarrays\n\t\t# such that the value of the maximum array element in that\n\t\t# sub... | 24 | 0 | [] | 2 |
number-of-subarrays-with-bounded-maximum | [Cpp] Concept , explanation and dry run | cpp-concept-explanation-and-dry-run-by-s-utn4 | For the element at each index we check below\n- If the current element is greater than R (A[i]>R) than we can not have any subarray ending with current element | spjparmar | NORMAL | 2020-07-04T12:13:39.911200+00:00 | 2020-07-04T12:14:06.645165+00:00 | 954 | false | For the element at each index we check below\n- If the current element is greater than R (A[i]>R) than we can not have any subarray ending with current element and we keep track of the current index for the future.\n- If current element is withing the range of L<=A[i]<=R than all possible subarrays ending with current ... | 22 | 0 | [] | 3 |
number-of-subarrays-with-bounded-maximum | Java O(n) concise solution with explanations | java-on-concise-solution-with-explanatio-nx0v | The idea is to consider the subarrays ending at each index i in the input array A. With i fixed, the subarray will be uniquely determined by its start index j, | fun4leetcode | NORMAL | 2018-03-04T16:14:29.383089+00:00 | 2018-03-04T16:14:29.383089+00:00 | 1,371 | false | The idea is to consider the subarrays ending at each index `i` in the input array `A`. With `i` fixed, the subarray will be uniquely determined by its start index `j`, and the subarray itself will be denoted as `A[j, i]` (left inclusive, right inclusive). If there are no additional constraints, `j` can take any integer... | 20 | 0 | [] | 2 |
number-of-subarrays-with-bounded-maximum | ✅ Number of Subarrays with Bounded Maximum | Easy Divide elements into Buckets w/Explanation | number-of-subarrays-with-bounded-maximum-5mqf | Thought Process:\n\n1) There can be three cases for every element in the array.\n* element < left (Case 1)\n* element <= right (Case 2)\n* element > right (Case | shivaye | NORMAL | 2021-06-17T07:26:14.430925+00:00 | 2021-06-17T09:46:08.805486+00:00 | 296 | false | **Thought Process:**\n```\n1) There can be three cases for every element in the array.\n* element < left (Case 1)\n* element <= right (Case 2)\n* element > right (Case 3)\n\n2) Case 1 and Case 2 are overlapping.\n* But we need to consider only that subarrays whose maximum element lies between [left,right].\n* This can ... | 19 | 17 | [] | 2 |
number-of-subarrays-with-bounded-maximum | Python Sliding Window | python-sliding-window-by-aayuskh-g1hr | \nclass Solution(object):\n def numSubarrayBoundedMax(self, A, L, R):\n """\n :type A: List[int]\n :type L: int\n :type R: int\n | aayuskh | NORMAL | 2020-12-31T23:05:06.231606+00:00 | 2020-12-31T23:05:06.231649+00:00 | 903 | false | ```\nclass Solution(object):\n def numSubarrayBoundedMax(self, A, L, R):\n """\n :type A: List[int]\n :type L: int\n :type R: int\n :rtype: int\n """\n # using Sliding window\n windowStart = count = curr = 0\n \n for windowEnd, num in enumerate(A)... | 18 | 1 | ['Sliding Window', 'Python'] | 3 |
number-of-subarrays-with-bounded-maximum | Python: Easy Explained, Linear time and constant space solution: Sliding Window Approach. | python-easy-explained-linear-time-and-co-qbu2 | Idea: Keep increasing the size of the window, till any element \'x\' is nums is not found such that x > right.\nOnce x is greater than right, shift the start of | meaditya70 | NORMAL | 2021-06-17T08:24:30.051120+00:00 | 2021-06-17T08:33:47.320512+00:00 | 1,170 | false | Idea: Keep increasing the size of the window, till any element \'x\' is nums is not found such that **x > right**.\nOnce x is greater than right, shift the start of the window to the element that occurs next after \'x\'.\n\nThere will be 3 possible cases:\n1. If a number is in the bound [left, right], we simply increme... | 17 | 1 | ['Sliding Window', 'Python'] | 2 |
number-of-subarrays-with-bounded-maximum | How to think when you meet the question?(thinking process) | how-to-think-when-you-meet-the-questiont-p346 | Considered straightly counting all the subarrays that have maximum value between (L, R).\nIt costs O(n^2) time and O(n^2) space.\n\n\nint numSubarrayBoundedMax( | txy3000 | NORMAL | 2018-09-22T19:37:42.014655+00:00 | 2018-10-25T04:33:49.895363+00:00 | 1,607 | false | Considered straightly counting all the subarrays that have maximum value between (L, R).\nIt costs O(n^2) time and O(n^2) space.\n\n```\nint numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n int l = A.size();\n int dp[l][l] = {0};\n\n for(int i = 0; i < l; ++i)\n for(int j = i + 1;... | 16 | 1 | [] | 1 |
number-of-subarrays-with-bounded-maximum | O(n) with easy readable comments | 100% faster | Java | on-with-easy-readable-comments-100-faste-r8jc | Please upvote if you find this simple to understand\n\npublic int numSubarrayBoundedMax(int[] nums, int left, int right) {\n \n // Initialize star | ankit03jangra | NORMAL | 2021-06-17T08:06:43.282712+00:00 | 2021-06-17T08:06:43.282746+00:00 | 894 | false | Please upvote if you find this simple to understand\n\npublic int numSubarrayBoundedMax(int[] nums, int left, int right) {\n \n // Initialize start and end with -1 \n int start = -1, end = -1, count = 0;\n for(int i=0; i<nums.length; i++){\n \n // If number less than le... | 14 | 3 | ['Java'] | 1 |
number-of-subarrays-with-bounded-maximum | Java 9 liner | java-9-liner-by-shawngao-fyyn | class Solution { public int numSubarrayBoundedMax(int[] A, int L, int R) { int res = 0; for (int i = 0; i < A.length; i++) { if | shawngao | NORMAL | 2018-03-04T04:04:59.415404+00:00 | 2018-10-24T06:37:43.662707+00:00 | 1,824 | false | ```
class Solution {
public int numSubarrayBoundedMax(int[] A, int L, int R) {
int res = 0;
for (int i = 0; i < A.length; i++) {
if (A[i] > R) continue;
int max = Integer.MIN_VALUE;
for (int j = i; j < A.length; j++) {
max = Math.max(max, A[j]);
... | 13 | 2 | [] | 1 |
number-of-subarrays-with-bounded-maximum | C++ Solution | Monotonic Stack modification | c-solution-monotonic-stack-modification-ryg64 | This appraoach is a modification Of monotonic stack to store the Previous Greater Element(pge) - (stored in vector named left) and Next Greater Element (nge) fo | its_gupta_ananya | NORMAL | 2021-05-10T07:00:44.729549+00:00 | 2021-06-17T14:04:32.387192+00:00 | 1,210 | false | This appraoach is a modification Of monotonic stack to store the Previous Greater Element(pge) - (stored in vector named left) and Next Greater Element (nge) for every element(stored in vector named right).\nFor any element i, it forms a part of valid subarrays till it encounters it\'s next greater elements from the le... | 12 | 0 | ['C', 'Monotonic Stack', 'C++'] | 2 |
number-of-subarrays-with-bounded-maximum | Java O(n) Sliding Window | java-on-sliding-window-by-aswinsureshk-6g7b | For each window if the new element is in range (L,R), we add window size m=(j-i+1) to the count. This remains same until we get a new element in range (then we | aswinsureshk | NORMAL | 2019-07-30T04:34:43.268031+00:00 | 2019-09-12T15:27:07.210936+00:00 | 969 | false | For each window if the new element is in range (L,R), we add window size m=(j-i+1) to the count. This remains same until we get a new element in range (then we recompute window size m=j-i+1. If new element is greater than R, we update i to j and we set m=0;\n```\nclass Solution {\n public int numSubarrayBoundedMax(i... | 10 | 0 | [] | 3 |
number-of-subarrays-with-bounded-maximum | Java: Sliding Window , O(n) , passes 100% runtime | java-sliding-window-on-passes-100-runtim-vazp | \nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int leftPointer = 0, rightPointer = 0;\n int n = num | BlackHam33r | NORMAL | 2021-06-17T15:32:48.403237+00:00 | 2021-06-18T16:48:20.332950+00:00 | 752 | false | ```\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int leftPointer = 0, rightPointer = 0;\n int n = nums.length;\n int count = 0;\n int number = 0;\n while(leftPointer<n && rightPointer<n) {\n if(nums[rightPointer]>=left && ... | 9 | 0 | ['Sliding Window', 'Java'] | 2 |
number-of-subarrays-with-bounded-maximum | [CPP] O(N) time and O(1) space with explanation | cpp-on-time-and-o1-space-with-explanatio-1d7k | \nstatic auto fast=[]{ios_base::sync_with_stdio(false);cin.tie(nullptr);return 0;}();\n#define mod 1000000007\nclass Solution \n{\npublic:\n int numSubarrayB | himanshu__nsut | NORMAL | 2020-03-10T11:05:15.576197+00:00 | 2020-03-10T11:05:15.576229+00:00 | 440 | false | ```\nstatic auto fast=[]{ios_base::sync_with_stdio(false);cin.tie(nullptr);return 0;}();\n#define mod 1000000007\nclass Solution \n{\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, int R) \n {\n //for an element there are 3 cases possible:\n //case 1 :element is greater than R. In this c... | 9 | 0 | [] | 1 |
number-of-subarrays-with-bounded-maximum | C++ solution | O(N) - Time complexity | c-solution-on-time-complexity-by-kritika-ewcs | \nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n int n = nums.size();\n int si =0;//startin | kritika_12 | NORMAL | 2021-07-04T07:39:57.686949+00:00 | 2021-07-04T07:48:01.182200+00:00 | 893 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n int n = nums.size();\n int si =0;//starting index\n int ei = 0; //ending index\n int result =0, prev_count =0;\n while(ei < n){\n if(left <= nums[ei] && nums[ei]<= r... | 8 | 1 | ['C', 'C++'] | 0 |
number-of-subarrays-with-bounded-maximum | Number of Subarrays with Bounded Maximum || Simple Python Sliding Window | number-of-subarrays-with-bounded-maximum-oeu4 | \nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n windowStart=0\n count=0\n curr=0\n | techie_sis | NORMAL | 2021-06-17T07:17:19.515590+00:00 | 2021-06-17T07:17:58.195136+00:00 | 644 | false | ```\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n windowStart=0\n count=0\n curr=0\n \n for windowEnd, num in enumerate(nums):\n if left <= num <= right:\n curr = windowEnd - windowStart + 1\n ... | 8 | 2 | ['Sliding Window', 'Python', 'Python3'] | 1 |
number-of-subarrays-with-bounded-maximum | Python | Two pointer technique | Easy solution | python-two-pointer-technique-easy-soluti-06ij | Do hit like button if helpful!!!!\n\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n start,end = - | __Asrar | NORMAL | 2022-07-19T12:38:07.409751+00:00 | 2022-07-19T12:38:07.409791+00:00 | 1,071 | false | ***Do hit like button if helpful!!!!***\n```\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n start,end = -1, -1\n res = 0\n for i in range(len(nums)):\n if nums[i] > right:\n start = end = i\n continue\... | 7 | 0 | ['Two Pointers', 'Python', 'Python3'] | 3 |
number-of-subarrays-with-bounded-maximum | Easy C++ solution || Simple approach with dry-run of example || O(N) time complexity | easy-c-solution-simple-approach-with-dry-bym6 | Intuition\nWe simply store the position of the current invalid number, i.e. the number with value greater than R and then subtract its position with the positio | prathams29 | NORMAL | 2023-06-30T10:08:50.188096+00:00 | 2023-06-30T10:09:41.881905+00:00 | 799 | false | # Intuition\nWe simply store the position of the current invalid number, i.e. the number with value greater than R and then subtract its position with the position of the current valid number and sum it over the array. \n`Example: nums = [1,2,5,3,4,1,2], L=3, R=4`\nInitially, ans = 0, left = -1 and right = -1\n`For i=... | 6 | 0 | ['Two Pointers', 'C++'] | 0 |
number-of-subarrays-with-bounded-maximum | Very simple Python3 and C++ with explanation | very-simple-python3-and-c-with-explanati-etkt | Whenever we come accross any counting subarray type of questions, the approach is to use two pointer and maintain a counter "num_subarrays" to keep the count of | geekcoder1989 | NORMAL | 2019-11-21T04:54:05.827473+00:00 | 2019-11-21T04:54:05.827540+00:00 | 405 | false | Whenever we come accross any counting subarray type of questions, the approach is to use two pointer and maintain a counter "num_subarrays" to keep the count of number of subarrays.\nLet i, j be the two pointers, then total number of subarrays from i:j is `num_subarrays += (j-i+1)`. see below for eg.\n[1 2 3]\ni | ... | 6 | 0 | [] | 1 |
number-of-subarrays-with-bounded-maximum | Sliding window Approach, Very easy to understand, faster than 97% | sliding-window-approach-very-easy-to-und-1wjy | Using the sliding window technique we first find the number of subarrays which have maximum value smaller than L and then we find the number of subarrays whose | 2020201089_janme | NORMAL | 2020-12-03T15:52:58.772125+00:00 | 2020-12-03T15:52:58.772172+00:00 | 255 | false | Using the sliding window technique we first find the number of subarrays which have maximum value smaller than L and then we find the number of subarrays whose maximum value is smaller than R+1. We subtract these two numbers to find the number of subarrays which have max value in [L,R]\n```\nint numSubarrayBoundedMax(v... | 5 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | java solution || easy to understand | java-solution-easy-to-understand-by-gau5-0bgt | Please UPVOTE if you like my solution!\n\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int count = 0,ans = | gau5tam | NORMAL | 2023-03-25T12:41:53.680441+00:00 | 2023-03-25T12:41:53.680483+00:00 | 591 | false | Please **UPVOTE** if you like my solution!\n```\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int count = 0,ans = 0,i = 0,j = 0;\n \n while(j<nums.length){\n if(nums[j]>right){\n count = 0;\n i = j+1;\n ... | 4 | 0 | ['Java'] | 0 |
number-of-subarrays-with-bounded-maximum | ✅ CPP || Explained with Comments || Easy Understanding || Sliding Window is everywhere | cpp-explained-with-comments-easy-underst-be6g | \n// super smart intuition\n // basic idea is to calculate how many subarrays possible such that\n // we include an element which satisfies >=left | ajinkyakamble332 | NORMAL | 2022-08-17T15:14:19.337853+00:00 | 2022-08-17T15:14:19.337885+00:00 | 482 | false | ```\n// super smart intuition\n // basic idea is to calculate how many subarrays possible such that\n // we include an element which satisfies >=left and <=right\n // i.e all subarrays with satisfying that element to be the maximum\n // suppose we start from 0th index\n \n\t\t//Case1 ... | 4 | 0 | ['Sliding Window', 'C++'] | 0 |
number-of-subarrays-with-bounded-maximum | [JAVA] 100% FAST SOLUTION WITH COMMENTS || TWO POINTERS | java-100-fast-solution-with-comments-two-ljoa | class Solution {\n\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int ans = 0; \n int i = 0; \n int j = 0;\n | avneetsingh2001 | NORMAL | 2022-07-19T19:01:16.833553+00:00 | 2022-07-19T19:01:16.833585+00:00 | 632 | false | class Solution {\n\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int ans = 0; \n int i = 0; \n int j = 0;\n int prev = 0;\n while(j<nums.length){\n if(nums[j]>=left && nums[j]<=right){\n prev = j-i+1; //if in range adding all su... | 4 | 0 | ['Two Pointers', 'Java'] | 3 |
number-of-subarrays-with-bounded-maximum | Easy to understand Java Solution (Beats 99%) [Java] | easy-to-understand-java-solution-beats-9-3lnm | The question asks us to count the subarrays where max element for that subarray lies in a particular range. It clearly means if there is say a single element in | innovatoronspree | NORMAL | 2021-06-21T16:32:00.941752+00:00 | 2021-06-21T16:34:42.427805+00:00 | 159 | false | The question asks us to count the subarrays where max element for that subarray lies in a particular range. It clearly means if there is say a single element in the subarray and we encounter another element in the array which is smaller than left, then without any hassle we can increment answer by 1, if it is out of ra... | 4 | 0 | [] | 1 |
number-of-subarrays-with-bounded-maximum | ✅ Number of Subarrays with Bounded Maximum| W/Explanation | Linear time,Logic+Maths | number-of-subarrays-with-bounded-maximum-spj3 | Consider following test case: \n\n\n\t\t[3,4,1,2,1,3]\n\t\tleft=3\n\t\tright=5\n Here, we can see that any element which is between left & right are always incl | Projan_179 | NORMAL | 2021-06-17T19:36:34.996907+00:00 | 2021-06-17T19:36:34.996953+00:00 | 137 | false | Consider following test case: \n\n\n\t\t[3,4,1,2,1,3]\n\t\tleft=3\n\t\tright=5\n* Here, we can see that any element which is between `left` & `right` are always included for counting in the answer without watching which element is maximum.\n* Now we can also notice that if any element which is less than `left` occurs t... | 4 | 1 | ['Math', 'C'] | 1 |
number-of-subarrays-with-bounded-maximum | Easy C++ stack solution || commented | easy-c-stack-solution-commented-by-saite-3b5j | \nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n \n //get the number of elements that are small | saiteja_balla0413 | NORMAL | 2021-06-17T08:51:36.718209+00:00 | 2021-06-17T13:13:34.532623+00:00 | 196 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n \n //get the number of elements that are smaller to the left and right of every element in nums\n\t\t/by calculating this we can get number of subarrays that can be formed with the ele as a maximum and i... | 4 | 1 | [] | 0 |
number-of-subarrays-with-bounded-maximum | SIMPLE TWO-POINTER COMMENTED C++ SOLUTION | simple-two-pointer-commented-c-solution-xanzv | IntuitionApproachComplexity
Time complexity:o(n)
Space complexity:O(1)
Code | Jeffrin2005 | NORMAL | 2024-07-23T12:49:28.818443+00:00 | 2025-02-18T16:45:41.260444+00:00 | 464 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:o(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 3 | 0 | ['C++'] | 0 |
number-of-subarrays-with-bounded-maximum | Sliding Window Solution | Python | 0(N) 0(1) clean code | 98 % memory efficent | 95 % faster | sliding-window-solution-python-0n-01-cle-894k | count of subarrays having maximum element between left and right will be difference of count of subarrays having maximum element as right and count of subarrays | abhisheksanwal745 | NORMAL | 2024-06-15T09:30:43.173360+00:00 | 2024-06-15T09:31:39.844941+00:00 | 395 | false | count of subarrays having maximum element between left and right will be difference of count of subarrays having maximum element as right and count of subarrays having maximum elements less than left. Rest solution is trivial.\n\n\n```\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, ri... | 3 | 1 | ['Sliding Window', 'Python3'] | 0 |
number-of-subarrays-with-bounded-maximum | C++ solution in O(N) | c-solution-in-on-by-sachin_kumar_sharma-weo1 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Sachin_Kumar_Sharma | NORMAL | 2024-04-14T02:07:14.553740+00:00 | 2024-04-14T02:07:14.553757+00:00 | 27 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $... | 3 | 0 | ['C++'] | 0 |
number-of-subarrays-with-bounded-maximum | Java || Beats 100% || Two Pointers O(N) time, O(1) space. | java-beats-100-two-pointers-on-time-o1-s-wtxk | Intuition\nTwo pointers\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThe main points in this problem are :\n- If we pick a subar | abhinayd | NORMAL | 2023-07-05T07:11:15.079189+00:00 | 2023-07-09T10:40:48.010452+00:00 | 546 | false | # Intuition\n**Two pointers**\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n**The main points in this problem are :**\n- If we pick a subarray it should contain a element within left and right .\n- The subarray should not contain a element greater than right due to which we can bre... | 3 | 0 | ['Two Pointers', 'Greedy', 'Sliding Window', 'Java'] | 3 |
number-of-subarrays-with-bounded-maximum | With Explanation Comments: Time: 82 ms (86.62%), Space: 52.2 MB (94.04%) | with-explanation-comments-time-82-ms-866-zq2j | Like it? ->Upvote please! \u30C4\n\nSolution 1: Two-Pointers Approach\n\nTC: O(n) //iterate the array\nSC: O(1)\nTime: 174 ms (11.26%), Space: 52.2 MB (68.61% | deleted_user | NORMAL | 2022-09-20T16:51:21.402425+00:00 | 2022-09-20T16:51:21.402465+00:00 | 603 | false | **Like it? ->Upvote please!** \u30C4\n\n**Solution 1: Two-Pointers Approach**\n\nTC: O(n) //iterate the array\nSC: O(1)\nTime: 174 ms (11.26%), Space: 52.2 MB (68.61%)\n\n\'\'\'\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n \n //initialize a counte... | 3 | 0 | ['Array', 'Two Pointers', 'C', 'C++'] | 1 |
number-of-subarrays-with-bounded-maximum | 📌JAVA || Easy || Sliding window || O(n)✅ | java-easy-sliding-window-on-by-soyebsark-44bt | If it helps, do an Upvote \u2B06\uFE0F\uD83C\uDD99 So others can also find it helpful\n\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int | soyebsarkar563 | NORMAL | 2022-07-06T05:31:56.698736+00:00 | 2022-07-06T05:33:06.338688+00:00 | 253 | false | **If it helps, do an Upvote \u2B06\uFE0F\uD83C\uDD99 So others can also find it helpful**\n```\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n \n int i=0;\n int j=0;\n int m=0;\n int count=0;\n \n while(j<nums.length){\n ... | 3 | 0 | ['Sliding Window', 'Java'] | 0 |
number-of-subarrays-with-bounded-maximum | JAVA| Time - o(n) | Space - o(1) | Two Pointer | java-time-on-space-o1-two-pointer-by-shi-glyg | ```\n // time:- o(n)\n // space:- o(1)\n \n int i=0;\n int j=0;\n int count=0;\n int prev_count=0;\n \n | shivangijain | NORMAL | 2021-09-17T14:03:37.636676+00:00 | 2021-09-17T14:03:37.636705+00:00 | 216 | false | ```\n // time:- o(n)\n // space:- o(1)\n \n int i=0;\n int j=0;\n int count=0;\n int prev_count=0;\n \n // only i varies\n while(i<nums.length){\n if(left <= nums[i] && nums[i]<=right){\n // it is in range\n c... | 3 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Java | O(N^2) to O(N) optimization | Intuition | java-on2-to-on-optimization-intuition-by-f9tl | Bruteforce solution is straightforward, we consider every possibility (all subarrays), maintain a maximum and as long as there is valid maximum within range we | apooos3 | NORMAL | 2021-06-17T15:43:46.070473+00:00 | 2021-06-17T15:46:00.799003+00:00 | 259 | false | Bruteforce solution is straightforward, we consider every possibility (all subarrays), maintain a maximum and as long as there is valid maximum within range we increment the count. But this results in **O(n<sup>2</sup>)**\n\nObservations:\n\t1. \tOnce we encounter an element, *j* which is greater than the maximum rang... | 3 | 0 | ['Array', 'Dynamic Programming', 'Java'] | 0 |
number-of-subarrays-with-bounded-maximum | [C++] trick of number of subarray | c-trick-of-number-of-subarray-by-codeday-vqc7 | Approach 1: trick of number of subarray [1]\nTime/Space Complexity: O(N); O(1)\n\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, | codedayday | NORMAL | 2021-06-17T15:04:04.164800+00:00 | 2021-06-17T15:04:04.164849+00:00 | 203 | false | Approach 1: trick of number of subarray [1]\nTime/Space Complexity: O(N); O(1)\n```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n return count(A, R) - count(A, L - 1);\n }\nprivate:\n // Count # of sub arrays whose max element is <= N\n int count(const vector<int>& A, i... | 3 | 1 | ['C'] | 1 |
number-of-subarrays-with-bounded-maximum | Java: Sliding Window | java-sliding-window-by-shreyas_kadiri-05a7 | ```\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int count = 0;\n int i = 0;\n int j = 0;\n | shreyas_kadiri | NORMAL | 2021-06-17T12:53:55.707303+00:00 | 2021-06-17T12:53:55.707351+00:00 | 175 | false | ```\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int count = 0;\n int i = 0;\n int j = 0;\n int windowSize = 0; \n \n while(j < nums.length){\n if(nums[j]>=left && nums[j]<=right){\n windowSize = j - i + ... | 3 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Python standard solution | python-standard-solution-by-adityachauha-97ch | \nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n end,start=-1,-1\n result=0\n for i | adityachauhan343 | NORMAL | 2021-06-17T10:26:40.453466+00:00 | 2021-06-17T10:26:40.453510+00:00 | 161 | false | ```\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n end,start=-1,-1\n result=0\n for i in range(len(nums)): \n if nums[i]>=left and nums[i]<=right:\n end=i\n result+=end-start\n elif nums[i]... | 3 | 1 | ['Python'] | 0 |
number-of-subarrays-with-bounded-maximum | Java || Sliding Window + DP || 2ms || beats 100% || T.C - O(N) S.C - O(1) | java-sliding-window-dp-2ms-beats-100-tc-0s4w6 | \n // O(A.length) O(1)\n\tpublic int numSubarrayBoundedMax(int[] A, int L, int R) {\n\n\t\tint len = A.length, sum = 0, count = 0, j = -1;\n\t\tfor (int i = | LegendaryCoder | NORMAL | 2021-05-01T12:22:10.148664+00:00 | 2021-05-01T12:22:10.148695+00:00 | 136 | false | \n // O(A.length) O(1)\n\tpublic int numSubarrayBoundedMax(int[] A, int L, int R) {\n\n\t\tint len = A.length, sum = 0, count = 0, j = -1;\n\t\tfor (int i = 0; i < len; i++) {\n\n\t\t\tif (A[i] >= L && A[i] <= R) {\n\t\t\t\tcount = i - j;\n\t\t\t\tsum += count;\n\t\t\t} else if (A[i] < L) {\n\t\t\t\tsum += count;\n\... | 3 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | c++ solution | c-solution-by-dilipsuthar60-39d4 | \nclass Solution {\npublic:\n int find(vector<int>&nums,int k)\n {\n int j=0;\n int ans=0;\n for(int i=0;i<nums.size();i++)\n | dilipsuthar17 | NORMAL | 2021-04-13T08:15:01.953499+00:00 | 2021-04-13T08:15:01.953540+00:00 | 311 | false | ```\nclass Solution {\npublic:\n int find(vector<int>&nums,int k)\n {\n int j=0;\n int ans=0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]>k)\n {\n j=i+1;\n }\n ans+=i-j+1;\n }\n return ans;\n }\n int n... | 3 | 0 | ['C', 'C++'] | 0 |
number-of-subarrays-with-bounded-maximum | C++| Very simple code | c-very-simple-code-by-arpitsingh53-c5h9 | \n int atmost(vector<int>& A,int t)\n {\n int mx=INT_MIN;\n int res=0;\n int l=0;\n for(int i=0;i<A.size();i++)\n {\n | arpitsingh53 | NORMAL | 2020-08-05T11:16:54.276550+00:00 | 2020-08-05T11:16:54.276590+00:00 | 241 | false | ```\n int atmost(vector<int>& A,int t)\n {\n int mx=INT_MIN;\n int res=0;\n int l=0;\n for(int i=0;i<A.size();i++)\n {\n mx=max(mx,A[i]);\n \n if(mx>t)\n {\n while(l<=i)\n {\n l=l+1;\n\n ... | 3 | 0 | [] | 3 |
number-of-subarrays-with-bounded-maximum | C++ | Check within valid window | c-check-within-valid-window-by-wh0ami-0ewg | \nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n \n int n = A.size();\n int res = 0, left = -1, | wh0ami | NORMAL | 2020-06-20T11:06:58.843909+00:00 | 2020-06-20T11:06:58.843943+00:00 | 164 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n \n int n = A.size();\n int res = 0, left = -1, right = -1;\n \n for (int i = 0; i < n; i++) {\n if (A[i] >= L && A[i] <= R)\n right = i;\n else if (A[i]... | 3 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Python O(n) | python-on-by-prosun-8ei1 | \n def numSubarrayBoundedMax(self, A, L, R):\n """\n :type A: List[int]\n :type L: int\n :type R: int\n :rtype: int\n | prosun | NORMAL | 2018-04-21T19:38:43.656135+00:00 | 2018-08-23T21:08:28.702369+00:00 | 630 | false | ```\n def numSubarrayBoundedMax(self, A, L, R):\n """\n :type A: List[int]\n :type L: int\n :type R: int\n :rtype: int\n """\n start = 0\n lastMatch = None\n count = 0\n for idx in range(0, len(A)):\n num = A[idx]\n if num >= L ... | 3 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Java easy to understand | java-easy-to-understand-by-wangxlsb-yxqt | \nclass Solution {\n public int numSubarrayBoundedMax(int[] A, int L, int R) {\n int prevHigh = -1, sum = 0, prev = 0;\n for(int i = 0; i < A.l | wangxlsb | NORMAL | 2018-03-09T03:59:17.595544+00:00 | 2018-03-09T03:59:17.595544+00:00 | 335 | false | ```\nclass Solution {\n public int numSubarrayBoundedMax(int[] A, int L, int R) {\n int prevHigh = -1, sum = 0, prev = 0;\n for(int i = 0; i < A.length; i++) {\n if(A[i] >= L && A[i] <= R) {\n prev = i - prevHigh;\n }\n else if(A[i] > R){\n ... | 3 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | 4 lines C++ | 4-lines-c-by-kellybundy-tif6 | int numSubarrayBoundedMax(vector<int>& A, int L, int R) { int x = 0, y = 0, z = 0; for (int a : A) z += (++x *= a <= R) - (++y *= a < L); re | KellyBundy | NORMAL | 2018-03-04T09:11:35.301735+00:00 | 2018-03-04T09:11:35.301735+00:00 | 398 | false | int numSubarrayBoundedMax(vector<int>& A, int L, int R) {
int x = 0, y = 0, z = 0;
for (int a : A)
z += (++x *= a <= R) - (++y *= a < L);
return z;
}
`x` counts the subarrays whose maximum is low enough.
`y` counts the subarrays whose maximum is too low.
`z` counts the subar... | 3 | 0 | [] | 1 |
number-of-subarrays-with-bounded-maximum | Ridiculously Simple O(n)/O(1) Java Solution based on State Machine | ridiculously-simple-ono1-java-solution-b-oir9 | I literally submitted this in the last 10 seconds left in the contest and I'm surprised I didn't miss any corner cases, lol... Imagine you have a state machine. | wannacry89 | NORMAL | 2018-03-04T04:15:26.426915+00:00 | 2018-03-04T04:15:26.426915+00:00 | 701 | false | I literally submitted this in the last 10 seconds left in the contest and I'm surprised I didn't miss any corner cases, lol...
Imagine you have a state machine. You really only have the following two states:
1 - Since seeing the last >R element, you have not yet seen an [L,R]-element. (call "haveYet = false")
2 - S... | 3 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Simplest approach conceptually? - n Choose 2 | simplest-approach-conceptually-n-choose-cnohi | Intuition\n\nNumbers above the maximum bound (right) will never be included in any subarray, so just skip those. \n\nA number below the minimum (left) can be in | MoggleToggles | NORMAL | 2023-12-27T21:10:56.836938+00:00 | 2023-12-29T21:49:49.597506+00:00 | 17 | false | # Intuition\n\nNumbers above the maximum bound (right) will never be included in any subarray, so just skip those. \n\nA number below the minimum (left) can be included in a subarray, but it can\'t stand by itself, so just compute the total number of subarrays where all values are below the maximum, then subtract the n... | 2 | 0 | ['Kotlin'] | 0 |
number-of-subarrays-with-bounded-maximum | c++ | easy | fast | c-easy-fast-by-venomhighs7-19z7 | \n\n# Code\n\n\n class Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n return count(nums, right) - count( | venomhighs7 | NORMAL | 2022-11-20T12:09:11.083901+00:00 | 2022-11-20T12:09:11.083944+00:00 | 1,588 | false | \n\n# Code\n```\n\n class Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n return count(nums, right) - count(nums, left - 1);\n }\n int count(const vector<int>& nums, int bound) {\n int ans = 0, cnt = 0;\n for (int x : nums) {\n cnt = ... | 2 | 0 | ['C++'] | 0 |
number-of-subarrays-with-bounded-maximum | C++||Two Pointers||Easy to Understand | ctwo-pointerseasy-to-understand-by-retur-mn52 | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector& nums, int left, int right) \n {\n int res=0,l=-1,r=-1;\n for(int i=0;irigh | return_7 | NORMAL | 2022-09-03T09:54:03.349187+00:00 | 2022-09-03T09:54:03.349230+00:00 | 314 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) \n {\n int res=0,l=-1,r=-1;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]>right)\n l=i;\n if(nums[i]>=left)\n r=i;\n res+=r-l;\n... | 2 | 0 | ['Two Pointers', 'C'] | 1 |
number-of-subarrays-with-bounded-maximum | Easy C++ Solution | easy-c-solution-by-subhanshu_babbar-57p4 | \nclass Solution {\npublic:\n int Requirement(vector<int>& nums,int right,int left){\n int cnt=0,j=0;\n \n for(int i=0;i<nums.size();i++ | Subhanshu_Babbar | NORMAL | 2022-05-23T19:29:13.696484+00:00 | 2022-05-23T19:29:13.696523+00:00 | 242 | false | ```\nclass Solution {\npublic:\n int Requirement(vector<int>& nums,int right,int left){\n int cnt=0,j=0;\n \n for(int i=0;i<nums.size();i++){\n if(nums[i]>right) j=0;\n else j++;\n cnt+=j;\n }\n return cnt;\n }\n int numSubarrayBoundedMax(vect... | 2 | 0 | ['C'] | 0 |
number-of-subarrays-with-bounded-maximum | Best Explanation <10 lines || 2 pointer approach, No DP || Easy-Understanding | best-explanation-10-lines-2-pointer-appr-z820 | //FOR 1ST TEST CASE GIVEN IN QUESTUON-> FIND NUMBER OF SUBARRAYS WITH MAX ELEMENT GREATER THAN 1 AND SUBTRACT ALL THE SUBARRAYS WITH MAX ELEMENT GREATER THAN 3 | lavishmalik | NORMAL | 2022-05-01T20:43:10.887156+00:00 | 2022-05-01T20:45:17.522138+00:00 | 363 | false | //FOR 1ST TEST CASE GIVEN IN QUESTUON-> FIND NUMBER OF SUBARRAYS WITH MAX ELEMENT GREATER THAN 1 AND SUBTRACT ALL THE SUBARRAYS WITH MAX ELEMENT GREATER THAN 3 FROM IT\n//THIS WILL GIVE YOU ALL SUBARRAYS WITH MAX ELEMENT IN RANGE [2,3]\n//FOR [2,1,4,3] THERE WILL BE 9 SUBARRAYS I.E 2, 21 , 214 , 2143 , 14 , 4 , 143 , 4... | 2 | 0 | ['C', 'C++'] | 0 |
number-of-subarrays-with-bounded-maximum | Hints | Approach | Explanation | C++ | hints-approach-explanation-c-by-dangebvi-yuwl | Approach\n\nIn this question, we have to find max. no. of subaarays whose maximum number is in the range [L,R] both inclusive.\n\nHere the idea is we keep to po | dangebvishal | NORMAL | 2022-03-21T08:16:22.128681+00:00 | 2022-03-21T08:16:22.128724+00:00 | 143 | false | **Approach**\n\nIn this question, we have to find max. no. of subaarays whose maximum number is in the range [L,R] both inclusive.\n\nHere the idea is we keep to pointers to maintain a window (subarray) which is satisfying the condition.\nIf we see our window no longer satisfying the condition( i.e.max. of subarray is ... | 2 | 0 | ['C', 'C++'] | 0 |
number-of-subarrays-with-bounded-maximum | C++ two pointer | c-two-pointer-by-abhishek23a-pdwi | \nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n int first=0,sec=0,len=nums.size(),ans=0,cons=0;\n | abhishek23a | NORMAL | 2022-01-20T19:37:10.083502+00:00 | 2022-01-20T19:37:10.083536+00:00 | 177 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n int first=0,sec=0,len=nums.size(),ans=0,cons=0;\n bool check=true;\n while(sec<len){\n if(first==sec){\n if(nums[sec]>=left && nums[sec]<=right)\n a... | 2 | 0 | ['Two Pointers'] | 0 |
number-of-subarrays-with-bounded-maximum | [Java] solution with explanation beating 100% - O(N) | java-solution-with-explanation-beating-1-yhy9 | We will go through the nums once from left to right and count the valid subarrays ending at the current index. Summing up all the results will give us the final | heijinganghuasheng | NORMAL | 2021-11-27T20:50:15.854235+00:00 | 2021-11-27T20:51:12.951219+00:00 | 222 | false | We will go through the `nums` once from left to right and count `the valid subarrays ending at the current index`. Summing up all the results will give us the final result.\n\nFor each num, we can categorize them into three types:\n1. nums in between of [left, right]. We could construct valid subarrays ending with the ... | 2 | 0 | ['Java'] | 1 |
number-of-subarrays-with-bounded-maximum | Java | Sliding Window | java-sliding-window-by-aakashhsingla-510b | It would be little tricky to find subarrays with maximum value b/w a specific range. But, finding subarrays with maximum value till a max specified value would | aakashhsingla | NORMAL | 2021-11-23T18:19:27.302976+00:00 | 2021-11-23T18:19:27.303008+00:00 | 191 | false | It would be little tricky to find subarrays with maximum value b/w a specific range. But, finding subarrays with maximum value till a max specified value would be easy. So, what we could do is find number of subarrays with maximum value less than equal to **right** and find number of subarrays with maximum value less t... | 2 | 0 | ['Sliding Window', 'Java'] | 1 |
number-of-subarrays-with-bounded-maximum | java easy to understand solution 2 pointers O(n) | java-easy-to-understand-solution-2-point-kk2k | \nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int ans =0;\n int prevValueCount=0;\n int n = n | sinhaneha455 | NORMAL | 2021-07-16T05:37:44.603403+00:00 | 2021-07-16T05:37:44.603451+00:00 | 182 | false | ```\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int ans =0;\n int prevValueCount=0;\n int n = nums.length;\n int i=0;\n for(int j=0;j<n;j++){\n if(nums[j]>=left && nums[j]<=right){\n ans+=j-i+1;\n ... | 2 | 1 | ['Java'] | 0 |
number-of-subarrays-with-bounded-maximum | JAVA || Clean & Concise & Optimal Code || O(N) Time || Easy to Understand || 100% Faster Solution | java-clean-concise-optimal-code-on-time-5emhs | \nclass Solution {\n \n public int countSubarray (int[] nums, int bound) {\n \n int answer = 0, count = 0;\n \n for (int num : | anii_agrawal | NORMAL | 2021-06-20T00:10:10.700129+00:00 | 2021-06-20T00:10:10.700168+00:00 | 129 | false | ```\nclass Solution {\n \n public int countSubarray (int[] nums, int bound) {\n \n int answer = 0, count = 0;\n \n for (int num : nums) {\n count = num <= bound ? count + 1 : 0;\n answer += count;\n }\n \n return answer;\n }\n \n publ... | 2 | 1 | ['Java'] | 1 |
number-of-subarrays-with-bounded-maximum | Sliding Window | sliding-window-by-randomnumber7-oylg | They key is to keep on capturing the sliding window size whenever we get a number at end of sliding window that is in valid range.\n\nWhy does it work?\n1. If t | randomNumber7 | NORMAL | 2021-06-18T06:05:15.642231+00:00 | 2021-06-18T06:06:09.849663+00:00 | 138 | false | They key is to keep on capturing the sliding window size whenever we get a number at end of sliding window that is in valid range.\n\nWhy does it work?\n1. If the last element is found to be such a large number that it crosses the valid range (maxWindow > right) - In this case we reset our window. So the window with th... | 2 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Number of Subarrays with Bounded Maximum DYNAMIC PROGRAMMING Solution | number-of-subarrays-with-bounded-maximum-izp6 | INTUITION :-\nThere are three cases :-\n1. nums[i] > right\n2. nums[i] < left \n3. nums[i] >= left && nums[i] >= right\n\ndp[i] represents number of | grasper1 | NORMAL | 2021-06-18T04:27:54.308879+00:00 | 2021-06-18T06:31:18.335327+00:00 | 137 | false | INTUITION :-\nThere are three cases :-\n1. nums[i] > right\n2. nums[i] < left \n3. nums[i] >= left && nums[i] >= right\n\ndp[i] represents number of subarrays \n1. satisfying condition (3) above , and\n2. ending at nums[i] \n(nums[i] may or may not be maximum)\n\nCode :-\n```\nclass Solution {\npublic:\n ... | 2 | 0 | ['Dynamic Programming', 'C'] | 0 |
number-of-subarrays-with-bounded-maximum | Two Pointer Approach C++ | two-pointer-approach-c-by-alamin-tokee-jfks | \nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n int i=0, j=0;\n int count = 0;\n int | alamin-tokee | NORMAL | 2021-06-17T15:07:50.849153+00:00 | 2021-06-17T15:07:50.849195+00:00 | 202 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n int i=0, j=0;\n int count = 0;\n int prevCount=0;\n int n=nums.size();\n \n while(j < n){\n if(nums[j] >= left && nums[j] <= right){\n prevCount= j... | 2 | 0 | ['C'] | 0 |
number-of-subarrays-with-bounded-maximum | Easy solution in O(N) in cpp | easy-solution-in-on-in-cpp-by-iamhkr-f942 | \nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n int estart=0,send=0,elong=0,ans=0;\n for(in | iamhkr | NORMAL | 2021-05-30T06:49:59.585374+00:00 | 2021-05-30T06:49:59.585405+00:00 | 100 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n int estart=0,send=0,elong=0,ans=0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]>=left and nums[i]<=right)\n {\n elong=i-estart+1;// 2 1 4 3 3 4\n ... | 2 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Simple Java Solution | O(n) | simple-java-solution-on-by-sagarguptay2j-xioo | \nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int res = 0,n = nums.length,count = 0,dist = 0;\n bo | sagarguptay2j | NORMAL | 2021-05-18T07:52:11.682242+00:00 | 2021-05-18T07:52:11.682288+00:00 | 77 | false | ```\nclass Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n int res = 0,n = nums.length,count = 0,dist = 0;\n boolean flag = false;\n for(int i = 0;i<n;i++){\n if(nums[i] <= right)\n count++;\n else{ \n count ... | 2 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Python 3 - counting | python-3-counting-by-yunqu-kmd5 | Use 2 counters: count1 keeps track of the length of subarrays that do not exceed R. count2 keeps the length of the subarrays that also do not go below L. While | yunqu | NORMAL | 2021-04-01T13:22:12.707502+00:00 | 2021-04-01T13:22:26.800226+00:00 | 141 | false | Use 2 counters: `count1` keeps track of the length of subarrays that do not exceed R. `count2` keeps the length of the subarrays that also do not go below L. While if we have an element falling below L, we update the answer only based on the old value of `count2`, but we still keep `count1` incrementing.\n\n```python\n... | 2 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | DP Solution + Explanation | dp-solution-explanation-by-halfpolygon-hvh8 | \nA = [2,1,4,3]\nL = 2 ; R = 3\n\nSubarrays which sum to range[L,R]\n\n[2] O, [2,1] O , [1,4] X, [4,3] X, [2,3] X, [2,4] X\n\nWe use permutation\n\n dp[ , , , , | halfpolygon | NORMAL | 2021-03-16T13:18:33.461846+00:00 | 2021-03-16T13:18:33.461884+00:00 | 232 | false | \nA = [2,1,4,3]\nL = 2 ; R = 3\n\nSubarrays which sum to range[L,R]\n\n[2] O, [2,1] O , [1,4] X, [4,3] X, [2,3] X, [2,4] X\n\nWe use permutation\n\n* dp[ , , , , , i, ]\n* dp[i] : denotes max no of valid subarr ending with A[i]\n\n* Case 1: A[i] < L\nWe can only append A[i] with a valid subarr ending with A[i-1] hence... | 2 | 1 | ['Dynamic Programming', 'Python'] | 0 |
number-of-subarrays-with-bounded-maximum | C++ + Well explained + Easy + Linear time | c-well-explained-easy-linear-time-by-i_a-9qx5 | \nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n\t\t// Sum will store the total number of subarrays\n int sum | i_am_pringle | NORMAL | 2020-09-15T17:05:38.404924+00:00 | 2020-09-15T17:06:26.120049+00:00 | 209 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n\t\t// Sum will store the total number of subarrays\n int sum = 0;\n\t\t// Count will store count of all the elements with value <= R\n int count = 0;\n\t\t// X will store count of all the subarrays which has ma... | 2 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | [Java] O(N) with Monotonic Stack | java-on-with-monotonic-stack-by-yuhwu-6uto | \n public int numSubarrayBoundedMax(int[] A, int L, int R) {\n int n = A.length;\n int[] prevL = new int[n];\n int[] nextL = new int[n]; | yuhwu | NORMAL | 2020-09-12T21:20:49.601182+00:00 | 2020-09-12T21:20:49.601223+00:00 | 135 | false | ```\n public int numSubarrayBoundedMax(int[] A, int L, int R) {\n int n = A.length;\n int[] prevL = new int[n];\n int[] nextL = new int[n];\n Arrays.fill(nextL, n);\n Stack<Integer> decS = new Stack();\n for(int i=0; i<n; i++){\n while(!decS.isEmpty() && A[decS.pe... | 2 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | 795-Number of Subarrays with Bounded Maximum-Py All-in-One by Talse | 795-number-of-subarrays-with-bounded-max-3xgy | Get it Done, Make it Better, Share the Best -- Talse\nI). Slide Window\n| O(T): O(n) | O(S): O(1) | Rt: 340ms | \npython\n def numSubarrayBoundedMax(self, A: | talse | NORMAL | 2020-03-11T22:32:44.823031+00:00 | 2020-03-11T22:32:44.823067+00:00 | 85 | false | **Get it Done, Make it Better, Share the Best -- Talse**\n**I). Slide Window**\n| O(T): O(n) | O(S): O(1) | Rt: 340ms | \n```python\n def numSubarrayBoundedMax(self, A: List[int], L: int, R: int) -> int:\n rst = count = st = 0; \n for i in range(len(A)):\n if L <= A[i] <= R: \n ... | 2 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | C++ O(n) simple solution | c-on-simple-solution-by-gwqi-l6e7 | \nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n int count = 0, maxCurrent=-1, maxCurrentIndex = -1;\n | gwqi | NORMAL | 2018-08-19T09:24:01.290821+00:00 | 2018-09-05T09:40:56.566350+00:00 | 316 | false | ```\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n int count = 0, maxCurrent=-1, maxCurrentIndex = -1;\n for (int i = 0, j = 0; i < A.size(); ++i)\n {\n if (A[i] <= R)\n {\n if (A[i] >= L)\n maxCurr... | 2 | 0 | [] | 0 |
number-of-subarrays-with-bounded-maximum | [JAVA] 2 O(n) solutions | java-2-on-solutions-by-tyuan73-44sn | public int numSubarrayBoundedMax(int[] A, int L, int R) { int s = 0, ans = 0, c = 0; for(int i = 0; i < A.length; i++) { if (A[i] > R) { | tyuan73 | NORMAL | 2018-03-04T04:09:34.534153+00:00 | 2018-03-04T04:09:34.534153+00:00 | 325 | false | public int numSubarrayBoundedMax(int[] A, int L, int R) {
int s = 0, ans = 0, c = 0;
for(int i = 0; i < A.length; i++) {
if (A[i] > R) {
c = 0;
s = i+1;
} else if (A[i] >= L) {
c = i - s + 1;
ans += i - s + 1;
... | 2 | 1 | [] | 0 |
number-of-subarrays-with-bounded-maximum | Linear Time complexity , well explained | linear-time-complexity-well-explained-by-mkqs | Intuition 1For 1Number of possibilities are1
Total cases: 1
adding 1 more number 1,212
2Total cases: previous + size of current sub array -> 1 + 2 -> 3adding 1 | dev2411 | NORMAL | 2025-01-28T10:43:45.032560+00:00 | 2025-01-28T10:43:45.032560+00:00 | 71 | false | # Intuition 1
For **1**
Number of possibilities are
1
**Total cases: 1**
adding 1 more number **1,2**
12
2
**Total cases: previous + size of current sub array -> 1 + 2 -> 3**
adding 1 more number **1,2,3**
123
23
3
**Total cases: previous + size of current sub array -> 3 + 3 -> 6**
adding 1 more number *... | 1 | 0 | ['Array', 'Java'] | 0 |
number-of-subarrays-with-bounded-maximum | ✅Simple | Best Explanation | O(n) | simple-best-explanation-on-by-mridul__si-kd28 | Intuition\n Describe your first thoughts on how to solve this problem. \nTo count the number of subarrays where the maximum element lies between given bounds le | Mridul__Singh__ | NORMAL | 2024-07-21T18:40:51.913177+00:00 | 2024-07-21T18:40:51.913229+00:00 | 67 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo count the number of subarrays where the maximum element lies between given bounds left and right, we can leverage a sliding window approach. The idea is to keep track of valid subarrays as we iterate through the array and reset counter... | 1 | 0 | ['Array', 'Two Pointers', 'C', 'C++', 'Java'] | 0 |
number-of-subarrays-with-bounded-maximum | MONTONIC STACK OPPP | montonic-stack-oppp-by-adityaarora12-7xs5 | **Bold**# Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexit | adi_arr | NORMAL | 2024-06-13T19:34:37.391500+00:00 | 2024-06-13T19:34:37.391576+00:00 | 23 | false | ****************Bold****************# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your spa... | 1 | 0 | ['Python3'] | 0 |
number-of-subarrays-with-bounded-maximum | [C++] Scan with Prefix Sum, O(n), Explained with Simple Visualization | c-scan-with-prefix-sum-on-explained-with-47yi | Intuition\n### We can classify each element x into three categories:\n P: Good/Pivot i.e. left <= x <= right: it can form a Pivot\n L: Low/Aux i.e. x < left : i | fzh | NORMAL | 2024-06-07T21:08:06.071252+00:00 | 2024-06-07T21:08:06.071279+00:00 | 33 | false | # Intuition\n### We can classify each element x into three categories:\n* P: Good/Pivot i.e. left <= x <= right: it can form a Pivot\n* L: Low/Aux i.e. x < left : it can contribute to a nearby pivot if reachable.\n* H: High/Barrier i.e. right < x: it is a barrier that split the array into subarrays,\n and each subarra... | 1 | 0 | ['C++'] | 0 |
number-of-subarrays-with-bounded-maximum | Python sliding window w/ explanation. | python-sliding-window-w-explanation-by-r-h920 | Intuition\n Describe your first thoughts on how to solve this problem. \nUsing a sliding window, we can check for subarrays that have a maximum value that lies | rkv_086 | NORMAL | 2024-03-19T01:41:22.607410+00:00 | 2024-03-19T01:41:22.607432+00:00 | 131 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing a **sliding window**, we can check for subarrays that have a maximum value that lies within a range [left, right].\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe initialize **two pointers** that are used to... | 1 | 0 | ['Sliding Window', 'Python3'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.