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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
number-of-subsequences-that-satisfy-the-given-sum-condition | Image Explanation🏆- [Binary Exponentiation || Two Pointers || Pre-Computation] - C++/Java/Python | image-explanation-binary-exponentiation-sx7ub | Video Solution (Aryan Mittal) - Link in LeetCode Profile\nNumber of Subsequences That Satisfy the Given Sum Condition by Aryan Mittal\n\n\n\n# Approach & Intuti | aryan_0077 | NORMAL | 2023-05-06T01:51:10.796303+00:00 | 2023-05-06T02:01:25.107587+00:00 | 29,324 | false | # Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\n`Number of Subsequences That Satisfy the Given Sum Condition` by `Aryan Mittal`\n\n\n\n# Approach & Intution\n then we can make substrings out of that \n\t\t\tnext thing from this how many substrings we can make we need ... | 60 | 1 | ['C', 'C++'] | 3 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Python Two pointers Complete Explanation | python-two-pointers-complete-explanation-dsr8 | Show some love with upvotes if you found this helpful.Now,into the solution ===>\n\nSort the array, because subsequence is nothing but a subset.\n\nreason: A wi | akhil_ak | NORMAL | 2020-07-01T01:13:52.930558+00:00 | 2020-07-01T01:13:52.930591+00:00 | 7,885 | false | Show some love with upvotes if you found this helpful.Now,into the solution ===>\n\nSort the array, because subsequence is nothing but a subset.\n\nreason: A window can be maintained [imin,j] such that\nif A[imin]+A[j]<=target\n then,\n for all i such that imin<=i<j\n A[imin]+A[i] <= target is true.\n\n ... | 48 | 7 | [] | 7 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ Precomputed Pow | c-precomputed-pow-by-votrubac-4l3y | Similar to the other solutions, but with precomputing power of 2 modulo 10 ^ 9 + 7.\n\nWell, Python folks are in luck. In C++, computing 2 ^ n inline gives TLE. | votrubac | NORMAL | 2020-06-28T05:28:30.163989+00:00 | 2020-06-28T05:53:32.877480+00:00 | 7,727 | false | Similar to the other solutions, but with precomputing power of 2 modulo `10 ^ 9 + 7`.\n\nWell, Python folks are in luck. In C++, computing `2 ^ n` inline gives TLE. I could not find an efficient modulo power function. So, I just precomputed the `pow(i, 2) % mod` values iterativelly.\n\n```cpp\nint numSubseq(vector<int>... | 47 | 9 | [] | 5 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Python🔥Java🔥C++🔥Simple Solution🔥Easy to Understand | pythonjavacsimple-solutioneasy-to-unders-cmki | !! BIG ANNOUNCEMENT !!\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies relat | techwired8 | NORMAL | 2023-05-06T00:09:04.137864+00:00 | 2023-05-06T01:27:28.664094+00:00 | 9,096 | false | **!! BIG ANNOUNCEMENT !!**\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies related to computer science and data science to my current Subscribers. I planned to give for next 10,000 Subscribers as well. If you\'re interested **DON\'T FOR... | 45 | 1 | ['Binary Search', 'Sorting', 'C++', 'Java', 'Python3'] | 5 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Two Sum,Python solution, explained, O(nlogn) | two-sumpython-solution-explained-onlogn-i4lpx | 1.This problem is a manipulation of Two sum problem.\n\t2. In this problem, order of numbers of a subsequence doesn\'t matter as we just have to consider max an | avinashgaur | NORMAL | 2020-06-29T10:52:37.981272+00:00 | 2020-06-29T12:43:08.623037+00:00 | 4,788 | false | 1.This problem is a manipulation of Two sum problem.\n\t2. In this problem, order of numbers of a subsequence doesn\'t matter as we just have to consider max and min of subsequence.Therefore, a subsequence from i to j in original array is equivalent to array having same elements and same minimum and maximum value. For ... | 31 | 3 | ['Sliding Window', 'Python3'] | 6 |
number-of-subsequences-that-satisfy-the-given-sum-condition | BEST ANS EASIEST TWO POINTER APPROACH | best-ans-easiest-two-pointer-approach-by-fspx | Intuition\n Describe your first thoughts on how to solve this problem. \nTwo Pointer Approach as we have to make sure that our window\'s max-min<=target.\n\n# A | Carpediem02 | NORMAL | 2023-05-06T02:56:21.513867+00:00 | 2023-05-06T02:56:21.513903+00:00 | 5,572 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTwo Pointer Approach as we have to make sure that our window\'s max-min<=target.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe have to sort the given nums array so that we can apply two pointer approach.For th... | 30 | 0 | ['C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Code + Login Explanation | Python | code-login-explanation-python-by-morning-v9s4 | \nThe solution to the question lies in finding the number of possible subsequence between \nstart and end pointer.\n\nLet the first pointer be at index 0 and l | morningstar317 | NORMAL | 2021-01-07T18:39:46.858680+00:00 | 2021-01-07T18:40:10.180418+00:00 | 1,824 | false | ```\nThe solution to the question lies in finding the number of possible subsequence between \nstart and end pointer.\n```\nLet the first pointer be at index ```0``` and last pointer be at index ```n-1```.\n\nSteps to follow:\n1. Sort the array\n2. Find the ```start and end ```index such that ```A[start] + A[end] <= ... | 20 | 0 | ['Python'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java - O(n log(n)) - Binary Search | java-on-logn-binary-search-by-toberank1-6196 | \nIdea:\n\n1. Sort the array firstly, because of the binary search.\n2. Each time we fix a starting point, then use binary search to find the ending point\n3. o | toberank1 | NORMAL | 2020-06-28T10:10:14.881334+00:00 | 2020-06-28T10:11:43.643613+00:00 | 3,476 | false | \nIdea:\n\n1. Sort the array firstly, because of the binary search.\n2. Each time we fix a starting point, then use binary search to find the ending point\n3. once we got starting and endinng point, 2^(end-start) makes sense, because for each element we select or not to select\n\nTime Complexity: O(n log(n))\nSpace Com... | 19 | 1 | [] | 4 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ | Unique solution✅✅ | c-unique-solution-by-pathrinarayananmdu-z4pb | \nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n int count =0 ; \n int n = nums.size();\n vector<int>pow(n | pathrinarayananmdu | NORMAL | 2023-05-06T04:23:53.925706+00:00 | 2023-05-06T14:47:41.166243+00:00 | 2,327 | false | ```\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n int count =0 ; \n int n = nums.size();\n vector<int>pow(n,1);\n sort(nums.begin(), nums.end());\n for(int i =1;i<n;i++){\n pow[i] = (pow[i-1] * 2) % (1000000007 );\n }\n int l... | 15 | 0 | ['C'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | ✅ C++ | 2 pointers Simple Explanation | c-2-pointers-simple-explanation-by-ashok-5mxr | As we care about only min & max of a subseq ... we need not bother about the ordering of elems . so just sort the array and apply two pointers to count subseq t | ashoknitw | NORMAL | 2022-06-27T07:37:50.434747+00:00 | 2022-08-08T12:39:19.843137+00:00 | 3,729 | false | **As we care about only min & max of a subseq ... we need not bother about the ordering of elems . so just sort the array and apply two pointers to count subseq that has the i\'th elem as minimum and j\'th elem as the maximum**\n\n**proof :**\n```\n/*\n [3 5 6 6]\n i j\nsay i at 3 and j at 6.. rem 3 elem after 3... | 15 | 0 | ['Two Pointers', 'C'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Python || 96.44% Faster || Two Pointers || Sorting | python-9644-faster-two-pointers-sorting-y6phz | \nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n i,j=0,len(nums)-1\n c,mod=0,(10**9+7)\n nums.sort()\n | pulkit_uppal | NORMAL | 2022-11-27T17:50:17.877852+00:00 | 2022-11-27T17:53:40.795604+00:00 | 2,131 | false | ```\nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n i,j=0,len(nums)-1\n c,mod=0,(10**9+7)\n nums.sort()\n while i<=j:\n if nums[i]+nums[j]<=target:\n c+=pow(2,(j-i),mod)\n i+=1\n else:\n j-=1... | 13 | 1 | ['Two Pointers', 'Sorting', 'Python', 'Python3'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java solution | Easy to understand |beats 100% | Beginner friendly | java-solution-easy-to-understand-beats-1-142t | Intuition\n Describe your first thoughts on how to solve this problem. \nProblem requires finding the number of subsequences of the given array nums whose sum i | antovincent | NORMAL | 2023-05-06T08:40:55.078457+00:00 | 2023-05-06T08:40:55.078489+00:00 | 2,655 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nProblem requires finding the number of subsequences of the given array nums whose sum is less than or equal to target. Sorting the array nums in non-decreasing order allows us to apply a two-pointer approach to count such subsequences eff... | 12 | 0 | ['Java'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java two pointer with explanation | java-two-pointer-with-explanation-by-ank-74b1 | \nclass Solution {\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums); //Sorting so that we can get the min and max directly\n | ankitkumarmahato | NORMAL | 2022-01-17T18:15:04.143219+00:00 | 2022-01-17T18:15:04.143269+00:00 | 3,041 | false | ```\nclass Solution {\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums); //Sorting so that we can get the min and max directly\n int i=0,j=nums.length-1,count=0,mod=(int)1e9 + 7;\n int[] power=new int[nums.length]; //Calculating the power in the power array.\n power... | 10 | 0 | ['Two Pointers', 'Java'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | 🔥🔥 3-D Dynamic Programming Solution 🔥🔥 | 3-d-dynamic-programming-solution-by-nama-6env | Intuition\nExplore all sub sequencs\nKeep track of min and max element in subsequence\n\n\n# Approach\nBy the way this will give TLE \u203C\n\nAt each index mak | namanchandak | NORMAL | 2023-05-06T06:16:35.030457+00:00 | 2023-05-06T06:36:18.510110+00:00 | 1,781 | false | # Intuition\nExplore all sub sequencs\nKeep track of min and max element in subsequence\n\n\n# Approach\nBy the way this will give TLE \u203C\n\nAt each index make 2 calls\n 1 for pick the element into subsequence\n 2 for not pick the element into subsequence\n\nreturn all the cases where minimum and maximum element ... | 8 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy Explanation🔥Two Pointers | Cpp | Java | Python | Javascript🔥 | easy-explanationtwo-pointers-cpp-java-py-uoa9 | Intuition\nThe main idea behind this approach is to use two pointers to form pairs of indices (left, right) such that the sum of the minimum and maximum element | nandini-gangrade | NORMAL | 2023-05-06T01:47:17.477923+00:00 | 2023-05-06T01:52:49.197697+00:00 | 2,197 | false | # Intuition\nThe main idea behind this approach is to use two pointers to form pairs of indices (left, right) such that the sum of the minimum and maximum element in the subsequence formed by using the elements from nums[left] to nums[right] is less than or equal to the given target. To count all the subsequences that ... | 8 | 4 | ['Two Pointers', 'C++', 'Java', 'Python3', 'JavaScript'] | 6 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java | Two pointers | Beats 100% | 15 lines | java-two-pointers-beats-100-15-lines-by-sbc7k | Complexity\n- Time complexity: O(n*log(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \ | judgementdey | NORMAL | 2023-05-06T00:47:49.419940+00:00 | 2023-05-06T00:49:41.478414+00:00 | 3,856 | false | # Complexity\n- Time complexity: $$O(n*log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int numSubseq(int[] nums, int target) {\n var n = nums.length;\n Arrays.sort(nu... | 8 | 1 | ['Array', 'Two Pointers', 'Sorting', 'Java'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ Solution || Sliding Window || Easy to understand | c-solution-sliding-window-easy-to-unders-ylbj | we first sort the array to keep out minimum element at position and find the maximum subarrays that follow the condition.\nthe approach is similar to that of th | ngaur6834 | NORMAL | 2021-05-15T18:08:15.636267+00:00 | 2021-05-15T18:08:15.636308+00:00 | 1,889 | false | we first sort the array to keep out minimum element at position and find the maximum subarrays that follow the condition.\nthe approach is similar to that of the sliding window solution of the two sum problem.\nWhenever our sum is less than or equals to the target sum then we count the number of the subarrays.\n\nLets ... | 8 | 1 | ['C', 'Sliding Window'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C#, and TypeScript Solution 🔥🚀 with approach. ❇️✅ | c-and-typescript-solution-with-approach-4fsm9 | \u2B06\uFE0FLike|\uD83C\uDFAFShare|\u2B50Favourite\n\n\n\n# Complexity\n- Time complexity:\nO(n log n)\n\n- Space complexity:\n O(n)\n\ncsharp []\npublic class | arafatsabbir | NORMAL | 2023-05-06T05:36:15.372918+00:00 | 2023-05-06T05:36:15.372946+00:00 | 2,125 | false | # \u2B06\uFE0FLike|\uD83C\uDFAFShare|\u2B50Favourite\n\n\n\n# Complexity\n- Time complexity:\nO(n log n)\n\n- Space complexity:\n O(n)\n\n```csharp []\npublic class Solution {\n public int NumSubseq(int[... | 7 | 0 | ['Array', 'Two Pointers', 'Sorting', 'TypeScript', 'C#'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy JS solution Beats 95% online submissions | easy-js-solution-beats-95-online-submiss-joso | 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 | Viraj_Patil_092 | NORMAL | 2023-05-06T04:33:19.716428+00:00 | 2023-05-06T04:33:19.716479+00:00 | 2,088 | 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)$$ --... | 7 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'JavaScript'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | [ C++ ] | Binary Search + Binary Exponentiation | Easy Explanation | c-binary-search-binary-exponentiation-ea-tqk8 | Intuition\n Describe your first thoughts on how to solve this problem. \nSince we have to find Subsequences, Sorting will not hamper the result\n\nFor each inte | kshzz24 | NORMAL | 2023-05-06T04:32:30.508895+00:00 | 2023-05-06T04:32:30.508929+00:00 | 1,013 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince we have to find Subsequences, Sorting will not hamper the result\n\nFor each integer if we found the maximum value which can be accepted under the given conditions we can find all subsequences starting from that integer.\n\n# Prereq... | 7 | 0 | ['Binary Search', 'Sorting', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ solution (sorting + sliding window protocol) | c-solution-sorting-sliding-window-protoc-x8yt | \nCode:\nclass Solution {\npublic:\n \n int numSubseq(vector& nums, int target) {\n \n sort(nums.begin(), nums.end());\n \n in | pazamour | NORMAL | 2020-06-29T06:47:10.477529+00:00 | 2020-06-29T06:47:45.302427+00:00 | 1,884 | false | \nCode:\nclass Solution {\npublic:\n \n int numSubseq(vector<int>& nums, int target) {\n \n sort(nums.begin(), nums.end());\n \n int l = 0;\n int r = nums.size()-1;\n int ans = 0;\n long long por[nums.size()+1];\n por[0]=1;\n\t\t\n\t\t/// Also, we can reduce... | 7 | 0 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy Java solution || beginner friendly | easy-java-solution-beginner-friendly-by-9jhwj | Please UPVOTE if you like my solution!\n\nclass Solution {\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n int mod = 10 | gau5tam | NORMAL | 2023-05-06T17:25:17.901441+00:00 | 2023-05-06T17:25:17.901474+00:00 | 255 | false | Please **UPVOTE** if you like my solution!\n```\nclass Solution {\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n int mod = 1000000007;\n int [] arr =new int[nums.length];\n arr[0]=1;\n for(int i=1;i<nums.length;i++){\n arr[i] = (arr[i-1]*2)%mod;\... | 6 | 0 | ['Two Pointers', 'Sorting', 'Java'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java 27 ms Faster than 99.87% online submissions using sliding window and Sorting | java-27-ms-faster-than-9987-online-submi-4q2s | \nclass Solution {\n public int numSubseq(int[] nums, int target) {\n final int MODULO = 1000000007;\n int length=nums.length;\n Arrays. | tarushi | NORMAL | 2021-02-25T22:30:05.984555+00:00 | 2021-02-25T22:33:06.744622+00:00 | 2,091 | false | ```\nclass Solution {\n public int numSubseq(int[] nums, int target) {\n final int MODULO = 1000000007;\n int length=nums.length;\n Arrays.sort(nums);\n int[] power2 = new int[length + 1];\n power2[0] = 1;\n for (int i = 1; i <= length; i++)\n power2[i] = (power2[... | 6 | 0 | ['Sliding Window', 'Sorting', 'Java'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Two-Pointers Approach || Easy to Understand | two-pointers-approach-easy-to-understand-ztvq | Solution:\n\nThe given problem can be solved using two pointer technique.\n\nFirst, sort the given array.\n\nThen, we can consider each element in the array as | IAmMADMAX | NORMAL | 2023-05-06T08:35:43.543140+00:00 | 2023-05-06T08:35:43.543178+00:00 | 428 | false | **Solution:**\n\nThe given problem can be solved using two pointer technique.\n\nFirst, sort the given array.\n\nThen, we can consider each element in the array as the minimum element of a subsequence, and find the maximum element that can be included in the subsequence such that the sum of the minimum and maximum elem... | 5 | 0 | ['Two Pointers', 'Python3'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Optimized solution using Two Pointers with Binary Exponentiation | Solution explained in detail. | optimized-solution-using-two-pointers-wi-x470 | \n\n# Approach\nThe given problem requires counting the number of non-empty subsequences of an array of integers nums such that the sum of the minimum and maxim | priyanshu11_ | NORMAL | 2023-05-06T07:26:53.805508+00:00 | 2023-05-06T07:28:06.651270+00:00 | 2,109 | false | \n\n# Approach\nThe given problem requires counting the number of non-empty subsequences of an array of integers nums such that the sum of the minimum and maximum element on it is less than or equal to a given integer target. Since the answer may be large, the final result must be returned modulo 10^9 + 7.\n\nThe solut... | 5 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'C++', 'Java'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ || BINARY SEARCH || SORT || EASY TO UNDERSTAND | c-binary-search-sort-easy-to-understand-69rys | Intuition\n\nhere we need to find all subsequece.\nso find biggest element for (v[i]+x)<=target\nall element between [v[i] to x] possible ans v[i] must be inclu | ganeshkumawat8740 | NORMAL | 2023-05-06T06:55:41.646711+00:00 | 2023-05-06T07:12:16.051965+00:00 | 2,085 | false | # Intuition\n\nhere we need to find all subsequece.\nso find biggest element for (v[i]+x)<=target\nall element between [v[i] to x] possible ans v[i] must be included in subsequence.\n\n# Approach\nSORT ARRAY\nfind upper bound of target-v[i]. let\'s upperbound\'s index equal to x\nif(x<i)break;\nelse increment ans by (1... | 5 | 0 | ['Binary Search', 'Sorting', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | ✅C++ || Two-pointer || Set Theory || Sorting | c-two-pointer-set-theory-sorting-by-abhi-verz | \n\nT->O(n * log n) && S->O(n) [For storing the power of 2\'s in vector\n\n\tclass Solution {\n\tpublic:\n\t\tint numSubseq(vector& nums, int target) {\n\t\t\ti | abhinav_0107 | NORMAL | 2022-07-07T20:42:04.084134+00:00 | 2022-07-07T20:42:04.084181+00:00 | 1,537 | false | \n\n**T->O(n * log n) && S->O(n) [For storing the power of 2\'s in vector**\n\n\tclass Solution {\n\tpublic:\n\t\tint numSubseq(vector<int>& nums, int target) {\n\t\t\tint mod=1e9+7,n=nums.size();\n\t\t\tsort(n... | 5 | 0 | ['Two Pointers', 'C', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | JavaScript (JS) solution 🔥🔥🔥 Ultrafast 💯💯💯 | javascript-js-solution-ultrafast-by-abas-xmio | JavaScript solution\n\n\nvar numSubseq = function(nums, target) {\n const MOD = 1000000007;\n\n nums = nums.sort((a, b) => a - b);\n\n const pows = [1] | abashev | NORMAL | 2022-06-17T04:42:59.613381+00:00 | 2022-06-17T04:44:28.985461+00:00 | 1,212 | false | JavaScript solution\n\n```\nvar numSubseq = function(nums, target) {\n const MOD = 1000000007;\n\n nums = nums.sort((a, b) => a - b);\n\n const pows = [1];\n \n for (let i = 1; i < nums.length; i++) {\n pows.push(pows[i - 1] * 2 % MOD);\n }\n \n let left = 0;\n let right = nums.length ... | 5 | 1 | ['Two Pointers', 'Binary Search', 'Binary Tree', 'JavaScript'] | 3 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ | Two Pointer Solution | O(nlogn) | Explained | c-two-pointer-solution-onlogn-explained-erfry | Approach\n1. Sort the given nums array.\n2. For every index i from 0 to n-1 find the index j of largest number.\n3. The number of valid subsequences are 2^(j - | nikhil682 | NORMAL | 2021-10-26T05:45:53.073021+00:00 | 2021-10-26T05:45:53.073068+00:00 | 1,202 | false | Approach\n1. Sort the given nums array.\n2. For every index i from 0 to n-1 find the index j of largest number.\n3. The number of valid subsequences are 2^(j - i)\n\nI have stored the values from 2^0 to 2^(n-1) to avoid repeated computations.\n\n```\n int numSubseq(vector<int>& nums, int target) {\n \n ... | 5 | 0 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | FASTER THAN 100% TIME +100% SPACE | faster-than-100-time-100-space-by-shivam-3p4p | JAVA CODE IS:\n# \n\nclass Solution {\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n int res=0,mod=1000_000_000+7;\n | shivam_gupta_ | NORMAL | 2021-03-27T06:08:02.009534+00:00 | 2021-03-27T06:08:02.009562+00:00 | 790 | false | JAVA CODE IS:\n# \n```\nclass Solution {\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n int res=0,mod=1000_000_000+7;\n int pow[]=new int[nums.length+1];\n pow[0]=1;\n for(int i=1;i<=nums.length;i++)\n pow[i]=(pow[i-1]*2)%mod;\n int i=0,j=nums... | 5 | 1 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java+two pointer approch | javatwo-pointer-approch-by-puskin123-grsa | class Solution {\n public int numSubseq(int[] nums, int target) {\n\n//basically the total subsequences possible from start to end is the ans of that particu | puskin123 | NORMAL | 2020-09-04T10:18:33.685758+00:00 | 2020-09-05T13:13:21.496085+00:00 | 1,244 | false | class Solution {\n public int numSubseq(int[] nums, int target) {\n\n//basically the total subsequences possible from start to end is the ans of that particular start index\n \n\tArrays.sort(nums);\n int sp=0;\n int ans=0;\n int ep=nums.length-1;\n while(sp<=ep){\n if(nums[s... | 5 | 2 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java Solution | java-solution-by-mycafebabe-a58z | \nclass Solution {\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n int ans = 0;\n int n = nums.length;\n | mycafebabe | NORMAL | 2020-07-10T07:07:47.201027+00:00 | 2020-07-10T07:07:47.201074+00:00 | 1,024 | false | ```\nclass Solution {\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n int ans = 0;\n int n = nums.length;\n int mod = (int)(1e9 + 7);\n int[] pows = new int[n];\n pows[0] = 1;\n for (int i = 1; i < n; i++) {\n pows[i] = (pows[i - 1] ... | 5 | 1 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java Very Clean solution faster than 100% speed and space using Two Pointer O(nlogn) time | java-very-clean-solution-faster-than-100-7adc | \nclass Solution {\n private static final int MOD = 1000000007;\n public int numSubseq(int[] nums, int target) {\n long[] modPow = new long[nums.le | nambk314 | NORMAL | 2020-06-28T07:02:06.649834+00:00 | 2020-06-28T07:02:30.050459+00:00 | 2,101 | false | ```\nclass Solution {\n private static final int MOD = 1000000007;\n public int numSubseq(int[] nums, int target) {\n long[] modPow = new long[nums.length + 1];\n modPow[0] = 1;\n for (int i = 1; i < modPow.length; i++) {\n modPow[i] = 2 * modPow[i-1] % MOD;\n }\n \n ... | 5 | 1 | [] | 7 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C# 2 Pointer solution | c-2-pointer-solution-by-leoooooo-bl15 | \npublic class Solution\n{\n public int NumSubseq(int[] nums, int target)\n {\n Array.Sort(nums);\n long mod = (long)Math.Pow(10, 9) + 7;\n\ | leoooooo | NORMAL | 2020-06-28T05:15:23.852463+00:00 | 2020-06-28T05:25:12.899185+00:00 | 547 | false | ```\npublic class Solution\n{\n public int NumSubseq(int[] nums, int target)\n {\n Array.Sort(nums);\n long mod = (long)Math.Pow(10, 9) + 7;\n\t\t//Pre compute 2^N, since N is big in this question.\n long[] cnt = new long[nums.Length];\n cnt[0] = 1;\n for (int i = 1; i < nums.Le... | 5 | 2 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | JAVA CODE || Properly Explained With Diagram || Modified Two Sum Approach || | java-code-properly-explained-with-diagra-3cje | Intuition\n Describe your first thoughts on how to solve this problem. \nwe can use modified two sum approach to solve this.\n\n# Approach\n Describe your appro | shiivamtaneja | NORMAL | 2023-08-15T13:50:37.867409+00:00 | 2023-08-15T13:50:37.867434+00:00 | 391 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe can use modified two sum approach to solve this.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirstly we need to ensure that the array is sorted for this approach to work.\nNow we create a new array of the sa... | 4 | 0 | ['Java'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy Solution | C++ | Two pointer | Exponentiation | Beginner Friendly | easy-solution-c-two-pointer-exponentiati-ngly | \n\n# Approach\n- First, we sort the array.\n- We use the 2 pointer approach to check if the first and last element is greater or less than the target\n- If the | kvkvvats | NORMAL | 2023-05-06T14:00:56.311527+00:00 | 2023-05-06T17:00:40.338666+00:00 | 632 | false | \n\n# Approach\n- First, we sort the array.\n- We use the 2 pointer approach to check if the first and last element is greater or less than the target\n- If the condition is satisfied then we calculate the number of non-empty subsequences\n- Number of sequences is equal to 2^n where n is the difference b/w the first an... | 4 | 0 | ['Two Pointers', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | To Find Number of Subsequences That Satisfy the Given Sum Condition | to-find-number-of-subsequences-that-sati-w0kz | Approach\nFirstly sort the given array. Now set a right pointer to n-1 and left pointer to 0. Now check if nums[left] +nums[right] >target. This is because afte | _parthiv_saikia_ | NORMAL | 2023-05-06T13:20:43.372454+00:00 | 2023-05-06T13:33:18.279458+00:00 | 1,042 | false | # Approach\nFirstly sort the given array. Now set a right pointer to n-1 and left pointer to 0. Now check if nums[left] +nums[right] >target. This is because after sorting the smallest element will at left and largest element is on the right. If the sum is greater than target decrease the right pointer. If the sum is l... | 4 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'C++'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Very Easy Way || Precomputing || sorting || Binary Search || CPP | very-easy-way-precomputing-sorting-binar-m25z | 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 | shubham7447 | NORMAL | 2023-05-06T08:27:04.604240+00:00 | 2023-05-06T08:27:04.604285+00:00 | 416 | 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 | ['Math', 'Binary Search', 'Sorting', 'C++'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | [ C++ ] [ Dynamic Programming ] [ DP + Binary Search ] | c-dynamic-programming-dp-binary-search-b-uie7 | Code\n\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n | Sosuke23 | NORMAL | 2023-05-06T04:02:41.243023+00:00 | 2023-05-06T06:56:06.450377+00:00 | 2,102 | false | # Code\n```\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n long res = 0;\n int k = 1\'000\'000\'007;\n vector<long> dp(n + 1, 1);\n for(int i = 1; i <= n; ++i){\n dp[i] = (dp[i... | 4 | 0 | ['Binary Search', 'Dynamic Programming', 'C++'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ Easy Binary Search Solution | c-easy-binary-search-solution-by-beast_3-4tnx | So let us first look at the logic part, so consider an array [2,3,4,5] and target value 7 for this array . Now we know that for the first element i.e., 2 the up | Beast_376 | NORMAL | 2022-07-14T15:23:25.175972+00:00 | 2022-07-16T05:58:02.208741+00:00 | 877 | false | So let us first look at the logic part, so consider an array [2,3,4,5] and target value 7 for this array . Now we know that for the first element i.e., 2 the upper_bound value would be 5 (target-a[i]) . So we would add pow(2,3-0) in our answer (3 is index of 5 and 0 is index of 2). But the question arises why we consid... | 4 | 0 | ['Binary Search', 'Sorting', 'Binary Tree'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | python easy two-pointers + sorting solution | python-easy-two-pointers-sorting-solutio-vw1a | \nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n n = len(nums)\n \n nums.sort()\n i, j = 0, n-1\n | byuns9334 | NORMAL | 2022-01-20T05:59:24.395907+00:00 | 2022-01-20T05:59:24.395950+00:00 | 1,287 | false | ```\nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n n = len(nums)\n \n nums.sort()\n i, j = 0, n-1\n \n \n res = 0 \n NUM = 10**9+7\n while i <= j:\n if nums[i] + nums[j] > target:\n j -= 1\n ... | 4 | 0 | ['Two Pointers', 'Sorting', 'Python', 'Python3'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ two pointer approach , Time-O(nlogn) | c-two-pointer-approach-time-onlogn-by-dh-0gzs | class Solution {\npublic:\n int calpow(int a,int b)\n {\n if(b==0)return 1;\n \n int res=calpow(a,b/2);\n \n if(b%2==0) | dhruvjain04 | NORMAL | 2022-01-14T08:19:12.264546+00:00 | 2022-01-14T08:19:12.264577+00:00 | 841 | false | class Solution {\npublic:\n int calpow(int a,int b)\n {\n if(b==0)return 1;\n \n int res=calpow(a,b/2);\n \n if(b%2==0)\n {\n res=res*res;\n }\n else\n {\n res=res*a*res;\n }\n return res;\n }\n \n int numS... | 4 | 0 | ['Sorting'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | very easy cpp solution || 98 % faster | very-easy-cpp-solution-98-faster-by-vvd4-avdo | \nclass Solution {\npublic:\n \n \n \n int numSubseq(vector<int>& nums, int target) {\n long long power[100005], ans=0,n=nums.size();;\n | vvd4 | NORMAL | 2021-01-22T11:07:52.989771+00:00 | 2021-01-22T11:07:52.989805+00:00 | 470 | false | ```\nclass Solution {\npublic:\n \n \n \n int numSubseq(vector<int>& nums, int target) {\n long long power[100005], ans=0,n=nums.size();;\n \n power[0]=1;\n for(int i=1;i<n;i++)\n power[i]=(power[i-1]*2)%1000000007;\n \n sort(nums.begin(),nums.end());\n ... | 4 | 0 | [] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Go - O(N * log N) | go-on-log-n-by-p_a_r_u_s-6e5x | I don\'t think this one are medium complexity solutions. Hope nobody ask this during interview or just to 100% fail candidate.\nJust watch this video: https://w | p_a_r_u_s | NORMAL | 2020-09-17T05:42:45.717511+00:00 | 2020-09-17T06:07:43.780803+00:00 | 255 | false | I don\'t think this one are medium complexity solutions. Hope nobody ask this during interview or just to 100% fail candidate.\nJust watch this video: https://www.youtube.com/watch?v=xCsIkPLS4Ls\n\n```\nfunc numSubseq(nums []int, target int) int {\n\tconst MOD = 1000000007\n\texps := make([]int, len(nums))\n\tfor i:= r... | 4 | 0 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java simple sort and count | java-simple-sort-and-count-by-hobiter-cogp | See comments for explanation\n1, sort the array from min to max;\n\n2. for each different right tail number tail = nums[r], \nwe find the highest left head numb | hobiter | NORMAL | 2020-06-28T19:18:40.380514+00:00 | 2020-06-28T19:24:29.718875+00:00 | 873 | false | See comments for explanation\n1, sort the array from min to max;\n\n2. for each different right tail number tail = nums[r], \nwe find the highest left head number head = nums[l]:\nthat head + tail <= target (t for short); \nThen we can form a valid subsequence: head ... tail; \nany numver between tail and head could b... | 4 | 2 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy C++ Solution | Easy to Understand | easy-c-solution-easy-to-understand-by-sh-so6a | \n# Code\n\n#define mod 1000000007\nclass Solution {\npublic:\n long long power(long long base,long long n){\n long long ans=1;\n while(n!=0){\ | shubhaamtiwary_01 | NORMAL | 2023-10-11T12:17:45.624915+00:00 | 2023-10-11T12:17:45.624933+00:00 | 337 | false | \n# Code\n```\n#define mod 1000000007\nclass Solution {\npublic:\n long long power(long long base,long long n){\n long long ans=1;\n while(n!=0){\n if(n%2==1){\n ans=(ans*base)%mod;\n n--;\n }else{\n base=(base*base)%mod;\n ... | 3 | 0 | ['C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | [Python 3] From Brute force to Two Pointers Solution - Clean & Concise | python-3-from-brute-force-to-two-pointer-lqda | \u274C Solution 1: Brute force (TLE)\n- We try all non-empty subsequences of the nums array, finding the min and max elements within each subsequence. We then c | hiepit | NORMAL | 2023-08-28T09:02:53.271443+00:00 | 2023-08-29T17:09:30.289947+00:00 | 242 | false | **\u274C Solution 1: Brute force (TLE)**\n- We try all non-empty subsequences of the `nums` array, finding the `min` and `max` elements within each subsequence. We then check if `min + max <= target`; if so, the subsequence is valid.\n- If nums has N elements, then there will be `2^N` subsequences.\n\n```python\nclass ... | 3 | 0 | ['Two Pointers', 'Python3'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Beats 99.7% || C++ || Significance of 'int' and 'long long' || Binary Search | beats-997-c-significance-of-int-and-long-g6nl | \n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTo start, we arrange the numbers in the nums array in ascending order. This helps | AY73 | NORMAL | 2023-08-14T14:12:02.528101+00:00 | 2023-08-14T15:19:30.550188+00:00 | 48 | false | \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTo start, we arrange the numbers in the nums array in ascending order. This helps us navigate through the array more effectively.\n\nWe place i at the beginning of the array and j at the end.\n\nAs we move forward with the pointers, we... | 3 | 0 | ['Two Pointers', 'Binary Search', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | 🐍 [ Python ] Simple Solution | 🚀 Optimal | 🔢 Two Pointer Sum Approach | ⏱️ O(n*log(n)) Approach | python-simple-solution-optimal-two-point-x3vf | Runtime: 832 ms, faster than 68.92% of Python3 online submissions for Number of Subsequences That Satisfy the Given Sum Condition.\nMemory Usage: 29.5 MB, less | godemode12 | NORMAL | 2023-05-06T11:18:01.910409+00:00 | 2023-05-06T11:18:39.034469+00:00 | 77 | false | *Runtime: 832 ms, faster than 68.92% of Python3 online submissions for Number of Subsequences That Satisfy the Given Sum Condition.\nMemory Usage: 29.5 MB, less than 8.18% of Python3 online submissions for Number of Subsequences That Satisfy the Given Sum Condition.*\n\nhere\'s a step-by-step explanation of the solutio... | 3 | 0 | ['Array', 'Two Pointers', 'Sorting', 'Python'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Almost like editorial version but in JavaScript. :). Just watch. | almost-like-editorial-version-but-in-jav-492o | \n# Code\n\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar numSubseq = function(nums, target) {\n let n = nums. | AzamatAbduvohidov | NORMAL | 2023-05-06T09:11:22.166099+00:00 | 2023-05-06T09:11:22.166144+00:00 | 726 | false | \n# Code\n```\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar numSubseq = function(nums, target) {\n let n = nums.length;\n let mod = 1_000_000_007;\n nums.sort((a,b) => a - b);\n \n // Precompute the value of 2 to the power of each value.\n ... | 3 | 0 | ['JavaScript'] | 3 |
number-of-subsequences-that-satisfy-the-given-sum-condition | python3 code | python3-code-by-veenaayyannagari-ucei | 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 | veenaayyannagari | NORMAL | 2023-05-06T08:29:06.088612+00:00 | 2023-05-06T08:29:06.088649+00:00 | 2,155 | 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)$$ --... | 3 | 0 | ['Python3'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | 2 Pointers easy approach | 2-pointers-easy-approach-by-sowjanyasank-x7zm | Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to think of the subsequences having sum of minimum and maximum element less tha | sowjanyasanku | NORMAL | 2023-05-06T06:58:35.298834+00:00 | 2023-05-06T06:58:35.298930+00:00 | 55 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to think of the subsequences having sum of minimum and maximum element less than the target. For this we use the two pinter approach.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initially we consider... | 3 | 0 | ['C++'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy C++ solution using 2 pointers | easy-c-solution-using-2-pointers-by-anwe-6i0b | 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 | anwendeng | NORMAL | 2023-05-06T02:07:35.177480+00:00 | 2023-05-06T02:07:35.177511+00:00 | 1,318 | 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)$$ --... | 3 | 0 | ['Array', 'Two Pointers', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Beats 100%, check it out. | beats-100-check-it-out-by-seekerofmiracl-af7k | \n\n# Complexity\n- Time complexity: O(n * log(n)) - Time complexity of this function is dominated by the sorting operation. That is O(n*log n)\n- Space complex | SeekerOfMiracle | NORMAL | 2023-05-06T01:54:05.349473+00:00 | 2023-05-06T01:54:05.349505+00:00 | 3,105 | false | \n\n# Complexity\n- Time complexity: O(n * log(n)) - Time complexity of this function is dominated by the sorting operation. That is O(n*log n)\n- Space complexity: O(n) - array `arr` is created with `n` el... | 3 | 0 | ['JavaScript'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy Understand | Simple Method | Binary Exponentiation | Java | Python | C++✅ | easy-understand-simple-method-binary-exp-cuej | Intuition\n Describe your first thoughts on how to solve this problem. \nFirst, the array needs to be sorted so that the array is monotonic so that it easy to b | czshippee | NORMAL | 2023-05-06T00:07:17.229580+00:00 | 2023-05-06T01:43:37.098342+00:00 | 1,839 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst, the array needs to be sorted so that the array is monotonic so that it easy to be operational by binary search\n\n\n\... | 3 | 0 | ['Two Pointers', 'Binary Search', 'C++', 'Java', 'Python3'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | 🗓️ Daily LeetCoding Challenge May, Day 6 | daily-leetcoding-challenge-may-day-6-by-ugty1 | This problem is the Daily LeetCoding Challenge for May, Day 6. Feel free to share anything related to this problem here! You can ask questions, discuss what you | leetcode | OFFICIAL | 2023-05-06T00:00:18.240058+00:00 | 2023-05-06T00:00:18.240151+00:00 | 5,525 | false | This problem is the Daily LeetCoding Challenge for May, Day 6.
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 create... | 3 | 0 | [] | 15 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ Recursive Solution but got TLE | c-recursive-solution-but-got-tle-by-susn-r18q | int countSubseq(int index,int n,int sum,int target,vector &nums,vector&subseq){\n if(index == n){\n if(!subseq.empty()){\n int | Susnata_das | NORMAL | 2022-09-10T11:47:44.965196+00:00 | 2022-09-10T11:47:44.965238+00:00 | 1,850 | false | int countSubseq(int index,int n,int sum,int target,vector<int> &nums,vector<int>&subseq){\n if(index == n){\n if(!subseq.empty()){\n int minEle = *min_element(subseq.begin() , subseq.end());\n int maxEle = *max_element(subseq.begin() , subseq.end());\n if(m... | 3 | 0 | ['Recursion', 'C'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | [C++] Binary Search | c-binary-search-by-deepesh_dragoneel-l27x | \nclass Solution {\npublic:\n int power(long long x, long long y, long long p)\n {\n long long res = 1;\n x = x % p;\n if (x == 0) re | deepesh_dragoneel | NORMAL | 2022-04-15T07:06:56.716408+00:00 | 2022-04-15T07:06:56.716442+00:00 | 702 | false | ```\nclass Solution {\npublic:\n int power(long long x, long long y, long long p)\n {\n long long res = 1;\n x = x % p;\n if (x == 0) return 0;\n while (y > 0)\n {\n if (y & 1)\n res = (res*x) % p;\n y = y>>1;\n x = ((x%p)*(x%p)) %... | 3 | 0 | ['C', 'Binary Tree'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Help me to memorize. | help-me-to-memorize-by-hekarket-69b5 | \nclass Solution {\n public int numSubseqUtil(int min, int max, int i, int[] nums, int target ){\n if(i == nums.length) return 0;\n int newMin | HekarKET | NORMAL | 2022-03-26T15:51:27.838163+00:00 | 2022-03-26T15:52:37.693679+00:00 | 1,553 | false | ```\nclass Solution {\n public int numSubseqUtil(int min, int max, int i, int[] nums, int target ){\n if(i == nums.length) return 0;\n int newMin = Math.min(min, nums[i]);\n int newMax = Math.max(max, nums[i]);\n\t\tint count = 0;\n if(newMax+newMin<=target){\n count += 1;\n ... | 3 | 0 | ['Recursion', 'Java'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | 2 pointers easy Python solution | 2-pointers-easy-python-solution-by-facep-yv1p | \tnums.sort()\n\tn = len(nums)\n\ti, j = 0, n - 1\n\tresult = 0\n\twhile i <= j:\n\t\tif nums[i] + nums[j] <= target:\n\t\t\tresult += 2 ** (j - i)\n\t\t\ti += | FACEPLANT | NORMAL | 2021-03-26T15:30:10.264915+00:00 | 2021-03-26T15:30:10.264953+00:00 | 348 | false | \tnums.sort()\n\tn = len(nums)\n\ti, j = 0, n - 1\n\tresult = 0\n\twhile i <= j:\n\t\tif nums[i] + nums[j] <= target:\n\t\t\tresult += 2 ** (j - i)\n\t\t\ti += 1\n\t\telse:\n\t\t\tj -= 1\n\treturn result % (10 ** 9 + 7) | 3 | 2 | [] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ | 2 Pointer with easy explanation | upvote if you liked the approach | O(nlogn) time complexity | c-2-pointer-with-easy-explanation-upvote-tyip | \nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n // sort the array, to get the right pairs optimally\n sort(nums. | swapnilkant11 | NORMAL | 2020-09-01T06:59:49.544334+00:00 | 2020-09-14T12:12:12.180862+00:00 | 606 | false | ```\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n // sort the array, to get the right pairs optimally\n sort(nums.begin(), nums.end());\n int len = nums.size();\n // take a temp array to store the number values, once taking the number and once ignoring it\n... | 3 | 1 | [] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | From brute force backtracking to efficient Two pointer solution | from-brute-force-backtracking-to-efficie-7fvl | Bactracking solution - TLE\n\nclass Solution {\n int count = 0;\n int modulo = (int)Math.pow(10, 9) + 7;\n public int numSubseq(int[] nums, int target) | gagrawa3 | NORMAL | 2020-07-25T17:18:59.998205+00:00 | 2020-07-25T17:18:59.998258+00:00 | 632 | false | Bactracking solution - TLE\n```\nclass Solution {\n int count = 0;\n int modulo = (int)Math.pow(10, 9) + 7;\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n backtrack(new ArrayList<Integer>(), nums, target, 0);\n return count%modulo;\n }\n \n private void ba... | 3 | 0 | [] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | cpp solution two pointers + math | cpp-solution-two-pointers-math-by-huowa2-7tz4 | \n\n\nclass Solution {\npublic:\n int numSubseq(vector<int> &nums, int target) {\n sort(nums.begin(), nums.end()); \n long long ret = 0;\n | huowa222 | NORMAL | 2020-07-09T04:48:57.269251+00:00 | 2020-07-09T04:48:57.269299+00:00 | 443 | false | ```\n\n\nclass Solution {\npublic:\n int numSubseq(vector<int> &nums, int target) {\n sort(nums.begin(), nums.end()); \n long long ret = 0;\n int left = 0, right = nums.size() - 1;\n while(left <= right) {\n if(nums[left] + nums[right] > target) right--;\n else {\n... | 3 | 0 | [] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Can Somebody Help me with this Code?? | can-somebody-help-me-with-this-code-by-m-qtku | \n\nIs it Overflow? or is the code wrong?\nCan Math.pow() compute values like 2^10000 and hold them??\n\n\nclass Solution \n{\n public int numSubseq(int[] A, | MasterBruce | NORMAL | 2020-06-28T13:53:59.940287+00:00 | 2020-06-28T15:05:32.999727+00:00 | 286 | false | \n\n**Is it Overflow? or is the code wrong?**\n**Can Math.pow() compute values like 2^10000 and hold them??**\n\n```\nclass Solution \n{\n public int numSubseq(int[] A, int target) {\n Arrays.sort(A);\... | 3 | 1 | [] | 5 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Binary Search | Beats 61% | Python3 | binary-search-beats-61-python3-by-alpha2-9ykt | Please UpvoteCode | Alpha2404 | NORMAL | 2025-03-20T11:01:13.373413+00:00 | 2025-03-20T11:01:13.373413+00:00 | 87 | false | # Please Upvote
# Code
```python3 []
class Solution:
def numSubseq(self, nums: List[int], target: int) -> int:
N = len(nums)
count = 0
MOD = 10**9+7
nums.sort()
for i in range(N):
j = bisect_right(nums,target-nums[i]) - 1
if j >= i:
co... | 2 | 0 | ['Array', 'Binary Search', 'Sorting', 'Python3'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | ✅ C++ Solution - 2 pointers O(nlogn) TC O(n) SC ✅ | c-solution-2-pointers-onlogn-tc-on-sc-by-zp6o | Code\n\nclass Solution {\npublic:\n int mod = 1e9+7;\n vector<int> pow(int b,int n){\n vector<int> power(n+1);\n power[0]=1;\n for(in | ADreamOfMine | NORMAL | 2024-10-23T16:10:44.150980+00:00 | 2024-10-23T16:12:47.933902+00:00 | 149 | false | ## Code\n```\nclass Solution {\npublic:\n int mod = 1e9+7;\n vector<int> pow(int b,int n){\n vector<int> power(n+1);\n power[0]=1;\n for(int i=1;i<=n;i++){\n power[i]=(power[i-1]*b)%mod;\n }\n return power;\n }\n int numSubseq(vector<int>& nums, int target) {\n ... | 2 | 0 | ['Array', 'Two Pointers', 'Sorting', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Number of Subsequences That Satisfy the Given Sum Condition C++ Solution | number-of-subsequences-that-satisfy-the-3j7xz | 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 | rissabh361 | NORMAL | 2023-09-07T05:18:22.867831+00:00 | 2023-09-07T05:18:22.867854+00:00 | 74 | 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)$$ --... | 2 | 0 | ['C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java || Recursion&Memo|| Subsequence logic (Explained) || Passes 45/62(TLE) | java-recursionmemo-subsequence-logic-exp-hm65 | ```\nclass Solution {\n private static final int MOD = (int) (1e9 + 7);\n\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n | kurmiamreet44 | NORMAL | 2023-05-21T19:42:34.601467+00:00 | 2023-05-21T19:42:34.601506+00:00 | 1,176 | false | ```\nclass Solution {\n private static final int MOD = (int) (1e9 + 7);\n\n public int numSubseq(int[] nums, int target) {\n Arrays.sort(nums);\n Map<String, Integer> memo = new HashMap<>();\n long ans = helper(nums, Integer.MAX_VALUE, Integer.MIN_VALUE, 0, target, memo);\n return (int... | 2 | 0 | ['Recursion', 'Java'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | 1498. Number of Subsequences That Satisfy the Given Sum Condition | 1498-number-of-subsequences-that-satisfy-wmiz | class Solution {\n int power(int b) {\n long long ans = 1, k = 2, mod = 1e9 + 7;\n while(b) {\n if(b % 2) ans = (ans * k) % mod;\n | pspraneetsehra08 | NORMAL | 2023-05-14T19:26:05.049923+00:00 | 2023-05-14T19:26:05.049965+00:00 | 18 | false | class Solution {\n int power(int b) {\n long long ans = 1, k = 2, mod = 1e9 + 7;\n while(b) {\n if(b % 2) ans = (ans * k) % mod;\n b /= 2;\n k = (k * k) % mod;\n }\n return ans;\n }\npublic:\n int numSubseq(vector<int>& nums, int target) {\n l... | 2 | 0 | ['C'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Ex-Amazon explains a solution with a video, Python, JavaScript, Java and C++ | ex-amazon-explains-a-solution-with-a-vid-3g6t | My youtube channel - KeetCode(Ex-Amazon)\nI create 165 videos for leetcode questions as of May 7, 2023. I believe my channel helps you prepare for the coming te | niits | NORMAL | 2023-05-06T20:06:43.190398+00:00 | 2023-05-06T20:06:43.190447+00:00 | 100 | false | # My youtube channel - KeetCode(Ex-Amazon)\nI create 165 videos for leetcode questions as of May 7, 2023. I believe my channel helps you prepare for the coming technical interviews. Please subscribe my channel!\n\n### Please subscribe my channel - KeetCode(Ex-Amazon) from here.\n\n**I created a video for this question.... | 2 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | CPP SOLUTION PROMINENT | cpp-solution-prominent-by-chayannn-xfmg | \n\n\n# Code\n\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n sort(nums.begin(),nums.end());\n int mod = 1e9+7;\ | Chayannn | NORMAL | 2023-05-06T19:23:34.828058+00:00 | 2023-05-06T19:23:34.828098+00:00 | 36 | false | \n\n\n# Code\n```\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n sort(nums.begin(),nums.end());\n int mod = 1e9+7;\n int i = 0;\n int j = num... | 2 | 0 | ['C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy C++ Solution || Pre-Computation || Two Pointer || T.C- O(nlogn) || S.C- O(n) | easy-c-solution-pre-computation-two-poin-7lsd | \n\n# Complexity\n- Time complexity:O(nlogn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) | karanjangir02 | NORMAL | 2023-05-06T18:27:19.890683+00:00 | 2023-05-06T18:27:19.890726+00:00 | 1,617 | false | \n\n# Complexity\n- Time complexity:O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n int ans=0;\n int n=nums.siz... | 2 | 0 | ['Two Pointers', 'C++'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C# O(Log N) memory, beats 100% by memory | c-olog-n-memory-beats-100-by-memory-by-d-wer3 | Intuition\nIn this problem, in order to compute powers of 2 for big exponents, most solutions use $O(N)$ memory to store each power of $2$ up to $N$ - length of | danlavrushko | NORMAL | 2023-05-06T18:26:51.063080+00:00 | 2023-05-07T03:59:39.688153+00:00 | 207 | false | # Intuition\nIn this problem, in order to compute powers of 2 for big exponents, most solutions use $O(N)$ memory to store each power of $2$ up to $N$ - length of `nums` array. This could be greatly optimizied, if we store only those powers which itself are powers of $2$, eg $2^1, 2^2, 2^4, 2^8 \\ldots$ and so on. And ... | 2 | 0 | ['C#'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Sort + Binary Search | C++ | sort-binary-search-c-by-tusharbhart-tjqj | \nclass Solution {\n int power(int b) {\n long long ans = 1, k = 2, mod = 1e9 + 7;\n while(b) {\n if(b % 2) ans = (ans * k) % mod;\n | TusharBhart | NORMAL | 2023-05-06T18:19:34.720713+00:00 | 2023-05-06T18:19:34.720746+00:00 | 98 | false | ```\nclass Solution {\n int power(int b) {\n long long ans = 1, k = 2, mod = 1e9 + 7;\n while(b) {\n if(b % 2) ans = (ans * k) % mod;\n b /= 2;\n k = (k * k) % mod;\n }\n return ans;\n }\npublic:\n int numSubseq(vector<int>& nums, int target) {\n ... | 2 | 0 | ['Binary Search', 'Sorting', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | c++ and JAVA sorting + two pointer with explanation | c-and-java-sorting-two-pointer-with-expl-xwi6 | Intuition\n Describe your first thoughts on how to solve this problem. \nhere arr[i] means sum of 2^i + 2^(i-1) + ....2^2 + 2^1 + 1\nThis is just to make the ca | vedantnaudiyal | NORMAL | 2023-05-06T16:24:57.264467+00:00 | 2023-05-06T17:01:26.838166+00:00 | 332 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nhere arr[i] means sum of 2^i + 2^(i-1) + ....2^2 + 2^1 + 1\nThis is just to make the calculations easier.\nWe will soon understand that since the subsequences can be generated using any no irrespective of their place but should be in orde... | 2 | 0 | ['C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | TWO POINTER APPROACH | two-pointer-approach-by-priyanka8d19-rqee | \n# Code\n\nconst int MOD = 1000000007;\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n sort(nums.begin(), nums.end());\ | priyanka8d19 | NORMAL | 2023-05-06T15:03:45.779670+00:00 | 2023-05-06T15:03:45.779701+00:00 | 1,063 | false | \n# Code\n```\nconst int MOD = 1000000007;\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n sort(nums.begin(), nums.end());\n int ans = 0;\n int l = 0, r = nums.size() - 1;\n \n vector<int>p2(nums.size());\n p2[0] = 1;\n for(int i = 1; i <... | 2 | 0 | ['C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Python short and clean. Functional programming. | python-short-and-clean-functional-progra-iw3b | Approach\nTL;DR, Similar to the Editorial solution, but written as a 1-liner.\n\n# Complexity\n- Time complexity: O(n * log(n))\n\n- Space complexity: O(n)\n\nw | darshan-as | NORMAL | 2023-05-06T13:47:04.379611+00:00 | 2023-05-06T13:47:04.379641+00:00 | 400 | false | # Approach\nTL;DR, Similar to the [Editorial solution](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/editorial/), but written as a 1-liner.\n\n# Complexity\n- Time complexity: $$O(n * log(n))$$\n\n- Space complexity: $$O(n)$$\n\nwhere, `n is length of nums`.\n\n# Code\n```pyt... | 2 | 0 | ['Two Pointers', 'Binary Search', 'Sorting', 'Python', 'Python3'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | A Game of long long || Upper Bound ||C++ | a-game-of-long-long-upper-bound-c-by-_dr-xc3p | Intuition\n Describe your first thoughts on how to solve this problem. \nIntuition is simple as we need to find upper bound for every digit in nums[i] if nums[i | _drigger | NORMAL | 2023-05-06T12:44:13.420571+00:00 | 2023-05-06T12:44:13.420620+00:00 | 56 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIntuition is simple as we need to find upper bound for every digit in nums[i] if nums[i] is twice greater than target than just return else find upper bound let\'s ay that is pos then find **pow(2,pos-i-1)** after this return ans+=pow. Ne... | 2 | 0 | ['Binary Search', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | GoLang Solution | golang-solution-by-debadev-dfpo | \n# Code\n\nimport(\n "sort"\n "math"\n "fmt"\n)\n\nfunc numSubseq(nums []int, target int) int {\n n, mod :=len(nums), math.Pow(10,9) + 7\n sort. | debadev | NORMAL | 2023-05-06T08:50:22.538296+00:00 | 2023-05-06T08:50:22.538334+00:00 | 277 | false | \n# Code\n```\nimport(\n "sort"\n "math"\n "fmt"\n)\n\nfunc numSubseq(nums []int, target int) int {\n n, mod :=len(nums), math.Pow(10,9) + 7\n sort.Ints(nums)\n\n var ans float64\n left, right := 0,n-1\n power:= make([]float64,n)\n power[0] = 1\n for i:=1;i<n;i++{\n power[i] = math.... | 2 | 0 | ['Go'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Short and Easy C++ solution | short-and-easy-c-solution-by-__akash_sin-afod | Intuition\nTwo Pointer and sorting\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nAs we are interested in subsequences, we can sor | __AKASH_SINGH___ | NORMAL | 2023-05-06T08:33:50.445958+00:00 | 2023-05-06T08:33:50.445985+00:00 | 918 | false | # Intuition\nTwo Pointer and sorting\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nAs we are interested in subsequences, we can sort the array,\nNow then we intialise two pointer at both end and find the potential min and max range and then we consider the min element as fix for cu... | 2 | 0 | ['C++'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | JAVA/PYTHON SOLUTION || BEATS 100% || EASY TO UNDERSTAND || 2 POINTER | javapython-solution-beats-100-easy-to-un-y6e5 | Approach\n Describe your approach to solving the problem. \nMake an array \'l\' of length n=length of nums,and insert 2^i in it, make sure that 2^i doest not ex | deleted_user | NORMAL | 2023-05-06T08:28:46.335296+00:00 | 2023-05-06T08:28:46.335338+00:00 | 423 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nMake an array \'l\' of length n=length of nums,and insert 2^i in it, make sure that 2^i doest not exceed 10^9+7.Now initialize two pointers left=0 and right=n-1 and check if sum of nums[left] and nums[right] is less than or equal to target or not. If ... | 2 | 0 | ['Java'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java | Python | C++ | Two-Pointer | java-python-c-two-pointer-by-rahulraturi-q9a2 | \nclass Solution\n{\n public:\n int numSubseq(vector<int> &nums, int target)\n {\n int n=nums.size();\n sort(nums.begin() | rahulraturi2002 | NORMAL | 2023-05-06T08:19:35.047149+00:00 | 2023-05-06T10:08:04.218783+00:00 | 516 | false | ```\nclass Solution\n{\n public:\n int numSubseq(vector<int> &nums, int target)\n {\n int n=nums.size();\n sort(nums.begin(), nums.end());\n int l = 0;\n int r = n - 1;\n int ans = 0;\n int mod = 1e9 + 7;\n\n vector<int> pow(n... | 2 | 0 | ['Two Pointers', 'C', 'Python', 'Java'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Easy beginner friendly sollution | easy-beginner-friendly-sollution-by-farh-h392 | \n# Approach\nmodified 2 sum approach\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n int | farhanc | NORMAL | 2023-05-06T08:19:16.108364+00:00 | 2023-05-06T08:19:16.108397+00:00 | 62 | false | \n# Approach\nmodified 2 sum approach\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n int mod=1e9+7;\n long power(int x,int y){\n if(y==0)return 1; \n if(y==1) return x;\n long ans=1;\n if(y%2==0){\n ans=... | 2 | 0 | ['C++'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Beginner Friendly || Clean Code || C++ | beginner-friendly-clean-code-c-by-somend-rutg | \n# Complexity\n- Time complexity: O(nLogn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) | somendrasingh019 | NORMAL | 2023-05-06T06:50:11.660276+00:00 | 2023-05-06T06:50:11.660304+00:00 | 72 | false | \n# Complexity\n- Time complexity: O(nLogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n int n=nums.size(),mod = 1000000007... | 2 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java Solution for Number of Sequences that Satisfy the Given Sum Condition Problem | java-solution-for-number-of-sequences-th-ui3s | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind the solution is to use a two-pointer approach to find all possible | Aman_Raj_Sinha | NORMAL | 2023-05-06T06:34:08.416786+00:00 | 2023-05-06T06:34:08.416818+00:00 | 176 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind the solution is to use a two-pointer approach to find all possible subsequences of the input array nums whose minimum and maximum elements sum up to a value less than or equal to the target.\n\n# Approach\n<!-- Descri... | 2 | 0 | ['Java'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java very easy O(nlogn) solution | java-very-easy-onlogn-solution-by-abhine-w4u5 | Intuition\n Describe your first thoughts on how to solve this problem. \n- We will use two pointer approach to solve this, it is same as two sum\n- Suppose we g | abhineshchandra1234 | NORMAL | 2023-05-06T06:33:22.178778+00:00 | 2023-05-06T06:33:22.178829+00:00 | 91 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We will use two pointer approach to solve this, it is same as two sum\n- Suppose we got index i & j such that nums[i] + nums[j] <= target. Then no of subsequence will be 2^(j-i).\n- In order to get i & j & apply two pointer we need to h... | 2 | 0 | ['Array', 'Two Pointers', 'Sorting', 'Java'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Binary Search is good | binary-search-is-good-by-_aman_gupta-4kn8 | # Intuition \n\n\n\n\n\n# Complexity\n- Time complexity: O(n * log(n))\n\n\n- Space complexity: O(log(n))\n\n\n# Code\n\nclass Solution {\n int n, mod = (i | _aman_gupta_ | NORMAL | 2023-05-06T06:16:10.378851+00:00 | 2023-05-06T06:16:10.378894+00:00 | 237 | 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 * log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(log(n))$$\n<!-... | 2 | 0 | ['Array', 'Binary Search', 'Sorting', 'Java'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | binary search + python3 | binary-search-python3-by-arana-o3an | Intuition\nSimilar to the editorial solution, but with binary search implemented in details\n\n\n# Complexity\n- Time complexity:\nO(NlogN)\n\n\n\n# Code\n\ncla | arana | NORMAL | 2023-05-06T06:10:37.843360+00:00 | 2023-05-06T06:10:37.843398+00:00 | 72 | false | # Intuition\nSimilar to the editorial solution, but with binary search implemented in details\n\n\n# Complexity\n- Time complexity:\nO(NlogN)\n\n\n\n# Code\n```\nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n nums = sorted(nums)\n #binary search, find the range that has m... | 2 | 0 | ['Binary Search', 'Python3'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ Very Simple Solution - Sorting, Two Pointers, Sliding Window, Memoization - Time : O(n*logn) | c-very-simple-solution-sorting-two-point-8vwn | Intuition\n Describe your first thoughts on how to solve this problem. \n1. Problem is to find subsequences. So, Order is not important, I can sort it.\n2. Two | yvrakesh | NORMAL | 2023-05-06T06:05:33.162849+00:00 | 2023-05-06T16:09:03.669632+00:00 | 931 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Problem is to find **subsequences**. So, Order is not important, I can **sort** it.\n2. **Two pointer approach**. Because we need minimum and maximum in that subsequence, Left pointer will be pointing minimum and right pointer pointing... | 2 | 0 | ['Two Pointers', 'Memoization', 'Sliding Window', 'Sorting', 'C++'] | 2 |
number-of-subsequences-that-satisfy-the-given-sum-condition | UPPER_BOUND | C++ | upper_bound-c-by-pajju_0330-qper | Code\n\nclass Solution {\npublic:\nint power(long long x, unsigned int y, int p)\n{\n int res = 1; \n x = x % p; \n if (x == 0) return 0; \n whi | Pajju_0330 | NORMAL | 2023-05-06T04:44:24.833945+00:00 | 2023-05-06T04:44:24.833984+00:00 | 501 | false | # Code\n```\nclass Solution {\npublic:\nint power(long long x, unsigned int y, int p)\n{\n int res = 1; \n x = x % p; \n if (x == 0) return 0; \n while (y > 0)\n {\n if (y & 1)\n res = (res*x) % p;\n y = y>>1; \n x = (x*x) % p;\n }\n return res;\n}\nint MOD = 1e9... | 2 | 0 | ['C++'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | 2_Pointor.py | 2_pointorpy-by-jyot_150-kqdj | Approach\nTwo Pointer\n\n# Complexity\n- Time complexity:\n O(n)\n\n\n# Code\n\nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n | jyot_150 | NORMAL | 2023-05-06T04:16:51.756439+00:00 | 2023-05-06T04:16:51.756479+00:00 | 759 | false | # Approach\nTwo Pointer\n\n# Complexity\n- Time complexity:\n $$O(n)$$\n\n\n# Code\n```\nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n nums.sort()\n ans=0\n i,j=0,len(nums)-1\n while i<=j:\n if nums[i]+nums[j]>target:\n j-=1\n ... | 2 | 0 | ['Python3'] | 1 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Sorting + Two Pointers technique || Simple And Easy C++ Solution || | sorting-two-pointers-technique-simple-an-z4cr | Intuition\nwe can apply two sum problem logic here for solving it.\n# Approach\n Describe your approach to solving the problem. \nsort the array and apply twosu | brucewayne_5 | NORMAL | 2023-05-06T03:46:58.331859+00:00 | 2023-05-06T03:50:50.680383+00:00 | 162 | false | # Intuition\nwe can apply two sum problem logic here for solving it.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nsort the array and apply twosum problem logic \nthe number of subsequences will be pow(2,subsequence length).\n# Complexity\n- Time complexity:\nO(NLOGN)\n- Space complexity:\n<!--... | 2 | 0 | ['Two Pointers', 'Sorting', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | 📌📌 C++ || Sorting || Two Pointers || Faster || Easy To Understand 🤷♂️🤷♂️ | c-sorting-two-pointers-faster-easy-to-un-87g3 | Sorting + Two Pointers\n\n Time Complexity :- O(NlogN)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int tar | __KR_SHANU_IITG | NORMAL | 2023-05-06T03:15:58.169319+00:00 | 2023-05-06T03:15:58.169352+00:00 | 531 | false | * ***Sorting + Two Pointers***\n\n* ***Time Complexity :- O(NlogN)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n int numSubseq(vector<int>& nums, int target) {\n \n int n = nums.size();\n \n long long mod = 1e9 + 7;\n \n // sort the nums\n ... | 2 | 0 | ['Two Pointers', 'C', 'Sorting', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | DAILY LEETCODE SOLUTION || EASY C++ SOLUTION | daily-leetcode-solution-easy-c-solution-qjc39 | \nconst int MOD=1e9+7;\nclass Solution {\npublic:\n long long powr(long long a,long long b){\n long long res=1;\n while(b){\n if(b&1 | pankaj_777 | NORMAL | 2023-05-06T02:41:42.813160+00:00 | 2023-05-06T02:41:42.813211+00:00 | 451 | false | ```\nconst int MOD=1e9+7;\nclass Solution {\npublic:\n long long powr(long long a,long long b){\n long long res=1;\n while(b){\n if(b&1) res=(res*a)%MOD;\n a=(a*a)%MOD;\n b=b>>1;\n }\n return res;\n }\n int lowerBound(vector<int>& nums,int target){\n... | 2 | 1 | ['Array', 'Two Pointers', 'C', 'Sorting', 'Binary Tree'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Python3 solution beats 95.78% 🚀🚀 || quibler7 | python3-solution-beats-9578-quibler7-by-odeoh | \n\n\n# Code\n\nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n nums.sort()\n l, r = 0, len(nums) - 1\n re | quibler7 | NORMAL | 2023-05-06T02:16:17.819090+00:00 | 2023-05-06T02:17:40.229828+00:00 | 64 | false | \n\n\n# Code\n```\nclass Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:\n nums.sort()\n l, r = 0, len(nums) - 1\n res = 0\n ... | 2 | 0 | ['Python3'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | C++ || O(n*(log(n) | c-onlogn-by-sagargupta1610-jf33 | Approach\n1. Sort given array.\n2. For each element from 1st onward find target-element index and put all element combination of total element in that range - 1 | Sagargupta1610 | NORMAL | 2023-05-06T02:09:17.630252+00:00 | 2023-05-06T02:14:51.530288+00:00 | 233 | false | # Approach\n1. Sort given array.\n2. For each element from 1st onward find target-element index and put all element combination of total element in that range - 1\n3. For finding all combination we used power of 2 with modulous of 1000000007 and add it in answer. \n\n# Complexity\n- Time complexity: $O(n*log(n))$\n<!--... | 2 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Sorting', 'C++'] | 0 |
number-of-subsequences-that-satisfy-the-given-sum-condition | Java | 2 pointers | Explained | java-2-pointers-explained-by-prashant404-i1eg | Idea:\n sum(min, max) must be \u2264 target, so it doesn\'t matter what the numbers in between are\n Number of subsequences of length n that must start with a g | prashant404 | NORMAL | 2023-05-06T01:56:54.578129+00:00 | 2023-05-06T01:56:54.578164+00:00 | 203 | false | **Idea:**\n* sum(min, max) must be \u2264 target, so it doesn\'t matter what the numbers in between are\n* Number of subsequences of length `n` that must start with a give number = 2 ^ (n - 1). This is because for each number except the first one, there is a choice to include it or exclude it, so 1 x 2 x 2 ... (n - 1) ... | 2 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | [Java/C++/Python] Clean Greedy Solution | javacpython-clean-greedy-solution-by-lee-kltu | Explanation\nCalculate the difference we need to change diff = abs(sum(A) - goal))\nWe can change at most limit once\nResult is the integer ceil of fraction dif | lee215 | NORMAL | 2021-03-07T04:11:11.796147+00:00 | 2021-03-07T04:20:32.885625+00:00 | 4,688 | false | # **Explanation**\nCalculate the difference we need to change `diff = abs(sum(A) - goal))`\nWe can change at most limit `once`\nResult is the integer ceil of fraction `diff / limit`.\nIn math it equals to `(diff + limit - 1) / limit`\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(1)`\n<br>\n\n**Java**\n```java\n p... | 57 | 5 | [] | 11 |
minimum-elements-to-add-to-form-a-given-sum | C++ 1-liner | c-1-liner-by-votrubac-qohd | We need to divide the difference between the sum and the goal by your limit. \n\nNote that you need one more element if there is remainder (difference % limit | votrubac | NORMAL | 2021-03-07T16:33:49.686886+00:00 | 2021-03-07T16:33:49.686932+00:00 | 1,632 | false | We need to divide the difference between the sum and the goal by your limit. \n\nNote that you need one more element if there is remainder (`difference % limit != 0`).\n\n```cpp\nint minElements(vector<int>& nums, int limit, int goal) {\n return (abs(accumulate(begin(nums), end(nums), 0l) - goal) + limit - 1) / lim... | 12 | 1 | [] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.