{"id":11871,"date":"2023-01-19T10:11:42","date_gmt":"2023-01-19T10:11:42","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=11871"},"modified":"2023-09-22T07:55:30","modified_gmt":"2023-09-22T07:55:30","slug":"subarray-with-given-sum","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/","title":{"rendered":"Finding SubArray with Given Sum"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg\" alt=\"\" \/><\/p>\n<p>The task of finding all subarrays with a given sum is a common problem in computer science and data analysis. Subarrays are contiguous segments of an array, and the challenge lies in efficiently identifying all such segments that sum up to a specified value. This problem has applications in various fields, including array manipulation, financial analysis, and data processing. In this article, we explore different approaches to solving the problem of finding all subarrays with a given sum. We delve into techniques that leverage prefix sums, hashing, and sliding windows to efficiently identify and extract the subarrays, providing insights into their advantages and limitations.<\/p>\n<h2>How to Find SubArray with Given Sum:<\/h2>\n<p>This problem is also known as subarray sum equals k. Given an array of non-negative integers and an integer sum, find a subarray that adds to a given sum. <\/p>\n<p><strong>Note:<\/strong>  There may be more than one subarray with sum as the given sum, print first such subarray. <\/p>\n<p><strong>Examples:<\/strong><\/p>\n<pre><code>Input: arr[] = [ 1, 20, 3, 10, 5 ], sum = 33<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109403952-SubArray%20with%20Given%20Sum1.png\" alt=\"\" \/><\/p>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>Sum found between indexes 1 and 3<\/code><\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nSum of elements between indices 1 and 3 is 20 + 3 + 10 = 33<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code>arr[] = [1, 4, 0, 0, 3, 10, 5], sum = 7<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>Sum found between indexes 1 and 4<\/code><\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nSum of elements between indices 1 and 4 is 4 + 0 + 0 + 3 = 7<\/p>\n<p><strong>Input:<\/strong><\/p>\n<pre><code>arr[] = [ 1, 4 ], sum = 0<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>No subarray found<\/code><\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nThere is no subarray with 0 sum<\/p>\n<h3>Approach 1 to Find SubArray with Given Sum<\/h3>\n<p>Find subarray with given sum using Nested loop<br \/>\nThe idea behind this approach is to consider all subarrays of the given array one by one and check the sum of every subarray.<\/p>\n<p><strong>Algorithm:<\/strong><br \/>\nRun two loops: the outer loop picks a starting point i and the inner loop tries all subarrays starting from j.<\/p>\n<p>Follow the steps given below to implement the approach:<\/p>\n<ul>\n<li>Traverse the array from start to end.<\/li>\n<li>From every index start another loop from i to the end of the array to get all subarrays starting from i, and keep a variable currentSum to calculate the sum of every subarray.<\/li>\n<li>For every index in inner loop update currentSum = currentSum + arr[j]<\/li>\n<li>If the currentSum is equal to the given sum then print the subarray.<\/li>\n<\/ul>\n<p>Below is the implementation of the above approach.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11874 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11874 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11874 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11874 .wpsm_nav-tabs > li.active > a, #tab_container_11874 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11874 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11874 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11874 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11874 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11874 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11874 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11874 .wpsm_nav-tabs > li > a:hover , #tab_container_11874 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11874 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11874 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11874 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11874 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11874 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11874 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11874 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11874 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11874 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11874 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11874 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11874\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11874\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11874_1\" aria-controls=\"tabs_desc_11874_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11874\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11874_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include &lt;bits\/stdc++.h&gt;\r\nusing namespace std;\r\n \r\n\/* Returns true if the there is a subarray\r\nof arr[] with sum equal to 'sum' otherwise\r\nreturns false. Also, prints the result *\/\r\nvoid subArraySum(int arr[], int n, int sum)\r\n{\r\n \r\n    \/\/ Pick a starting point\r\n    for (int i = 0; i &lt; n; i++) {\r\n        int currentSum = arr[i];\r\n \r\n        if (currentSum == sum) {\r\n            cout &lt;&lt; \"Sum found at indexes \" &lt;&lt; i &lt;&lt; endl;\r\n            return;\r\n        }\r\n        else {\r\n            \/\/ Try all subarrays starting with 'i'\r\n            for (int j = i + 1; j &lt; n; j++) {\r\n                currentSum += arr[j];\r\n \r\n                if (currentSum == sum) {\r\n                    cout &lt;&lt; \"Sum found between indexes \"\r\n                         &lt;&lt; i &lt;&lt; \" and \" &lt;&lt; j &lt;&lt; endl;\r\n                    return;\r\n                }\r\n            }\r\n        }\r\n    }\r\n    cout &lt;&lt; \"No subarray found\";\r\n    return;\r\n}\r\n \r\n\/\/ Driver Code\r\nint main()\r\n{\r\n    int arr[] = { 15, 2, 4, 8, 9, 5, 10, 23 };\r\n    int n = sizeof(arr) \/ sizeof(arr[0]);\r\n    int sum = 23;\r\n    subArraySum(arr, n, sum);\r\n    return 0;\r\n}\r\n<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11874 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11874 a\"),jQuery(\"#tab-content_11874\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output:<\/strong><\/p>\n<pre><code>Sum found between indexes 1 and 4<\/code><\/pre>\n<p><strong>Time Complexity:<\/strong> O(N2), Trying all subarrays from every index, used nested loop for the same<\/p>\n<p><strong>Auxiliary Space:<\/strong> O(1). <\/p>\n<h3>Approach 2 to Find SubArray With Given Sum<\/h3>\n<p>Find subarray with given sum using sliding window technique<br \/>\nThe idea is simple as we know that all the elements in subarray are positive so, If a subarray has sum greater than the given sum then there is no possibility that adding elements to the current subarray will be equal to the given sum. So the Idea is to use a similar approach to a sliding window technique.<\/p>\n<p><strong>Algorithm:<\/strong><br \/>\n<strong>Step 1:<\/strong> Start with an empty subarray<br \/>\n<strong>Step 2:<\/strong> add elements to the subarray until the sum is less than x( given sum ).<br \/>\n<strong>Step 3:<\/strong> If the sum is greater than x, remove elements from the start of the current subarray.<\/p>\n<p>Follow the steps given below to implement the approach:<\/p>\n<ul>\n<li>Create two variables, start=0, currentSum = arr[0]<\/li>\n<li>Traverse the array from index 1 to end.<\/li>\n<li>Update the variable currentSum by adding current element, currentSum = currentSum + arr[i]<\/li>\n<li>If the currentSum is greater than the given sum, update the variable currentSum as currentSum = currentSum \u2013 arr[start],<br \/>\nand update start as, start++.<\/li>\n<li>If the currentSum is equal to given sum, print the subarray and break the loop.<\/li>\n<\/ul>\n<p>Below is the implementation of the above approach.<br \/>\n\t\t\t\t\t\t\t<h3 style=\"margin-bottom:20px ;display:block;width:100%;margin-top:10px\">Subarray with given sum 2 <\/h3>\r\n\t\t\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11875 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11875 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11875 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11875 .wpsm_nav-tabs > li.active > a, #tab_container_11875 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11875 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11875 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11875 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11875 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11875 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11875 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11875 .wpsm_nav-tabs > li > a:hover , #tab_container_11875 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11875 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11875 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11875 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11875 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11875 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11875 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11875 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11875 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11875 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11875 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11875 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11875\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11875\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11875_1\" aria-controls=\"tabs_desc_11875_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11875\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11875_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n \r\n\/* Returns true if the there is a subarray of\r\narr[] with a sum equal to 'sum' otherwise\r\nreturns false. Also, prints the result *\/\r\nint subArraySum(int arr[], int n, int sum)\r\n{\r\n    \/* Initialize currentSum as value of\r\n    first element and starting point as 0 *\/\r\n    int currentSum = arr[0], start = 0, i;\r\n \r\n    \/* Add elements one by one to currentSum and\r\n    if the currentSum exceeds the sum,\r\n    then remove starting element *\/\r\n    for (i = 1; i &lt;= n; i++) {\r\n        \/\/ If currentSum exceeds the sum,\r\n        \/\/ then remove the starting elements\r\n        while (currentSum &gt; sum &amp;&amp; start &lt; i - 1) {\r\n            currentSum = currentSum - arr[start];\r\n            start++;\r\n        }\r\n \r\n        \/\/ If currentSum becomes equal to sum,\r\n        \/\/ then return true\r\n        if (currentSum == sum) {\r\n            cout &lt;&lt; \"Sum found between indexes \" &lt;&lt; start\r\n                 &lt;&lt; \" and \" &lt;&lt; i - 1;\r\n            return 1;\r\n        }\r\n \r\n        \/\/ Add this element to currentSum\r\n        if (i &lt; n)\r\n            currentSum = currentSum + arr[i];\r\n    }\r\n \r\n    \/\/ If we reach here, then no subarray\r\n    cout &lt;&lt; \"No subarray found\";\r\n    return 0;\r\n}\r\n \r\n\/\/ Driver Code\r\nint main()\r\n{\r\n    int arr[] = { 15, 2, 4, 8, 9, 5, 10, 23 };\r\n    int n = sizeof(arr) \/ sizeof(arr[0]);\r\n    int sum = 23;\r\n    subArraySum(arr, n, sum);\r\n    return 0;\r\n}\r\n<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11875 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11875 a\"),jQuery(\"#tab-content_11875\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t<\/p>\n<p><strong>Output:<\/strong> <\/p>\n<pre><code>Sum found between indexes 1 and 4<\/code><\/pre>\n<p><strong>Time Complexity:<\/strong> O(N)<br \/>\n<strong>Auxiliary Space:<\/strong> O(1). Since no extra space has been taken.<\/p>\n<p>Finally, we optimized our code and reduced our time complexity from O(N2) to O(N).<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nThe problem of finding all subarrays with a given sum presents interesting challenges and diverse solutions. While various techniques such as prefix sums, hashing, and sliding windows offer efficient ways to tackle this problem, the choice of approach depends on the specific characteristics of the data and the desired runtime complexity. Each technique has its strengths and trade-offs, and selecting the most suitable one involves understanding the problem requirements and considering factors such as memory usage, runtime efficiency, and ease of implementation. By mastering these techniques, programmers can efficiently solve this problem and apply their knowledge to a wide range of real-world scenarios.<\/p>\n<h2>FAQ related to subarray with given sum<\/h2>\n<p>Here are some FAQs related to subarray with given sum.<\/p>\n<p><strong>Q1: What is a subarray?<\/strong><br \/>\nA subarray is a contiguous segment of an array. For example, in the array [1, 2, 3, 4], [2, 3] is a subarray, and so is [1, 2, 3, 4].<\/p>\n<p><strong>Q2: What does it mean to find all subarrays with a given sum?<\/strong><br \/>\nThe task is to identify and list all subarrays within an array that sum up to a specified value.<\/p>\n<p><strong>Q3: Why is this problem important?<\/strong><br \/>\nThe problem has practical applications in scenarios such as financial data analysis, stock market predictions, and optimizing operations involving sequences of numbers.<\/p>\n<p><strong>Q4: What are some common approaches to solving this problem?<\/strong><br \/>\nApproaches include using prefix sums (cumulative sums), hashing techniques, and sliding windows. Prefix sums calculate cumulative sums for each position, hashing checks for previously encountered sums, and sliding windows maintain a moving subarray with the desired sum.<\/p>\n<p><strong>Q5: What is the time complexity of these techniques?<\/strong><br \/>\nThe time complexity varies based on the chosen technique. Prefix sums and sliding windows often have linear or near-linear complexity, while hashing-based methods can achieve linear complexity on average with considerations for hash collisions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The task of finding all subarrays with a given sum is a common problem in computer science and data analysis. Subarrays are contiguous segments of an array, and the challenge lies in efficiently identifying all such segments that sum up to a specified value. This problem has applications in various fields, including array manipulation, financial [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[163],"tags":[],"class_list":["post-11871","post","type-post","status-publish","format-standard","hentry","category-arrays"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Finding SubArray with Given Sum<\/title>\n<meta name=\"description\" content=\"Understanding what SubArray is and learning about how to find subarray with given sum using different approaches.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Finding SubArray with Given Sum\" \/>\n<meta property=\"og:description\" content=\"Understanding what SubArray is and learning about how to find subarray with given sum using different approaches.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-19T10:11:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-22T07:55:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Finding SubArray with Given Sum\",\"datePublished\":\"2023-01-19T10:11:42+00:00\",\"dateModified\":\"2023-09-22T07:55:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/\"},\"wordCount\":881,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg\",\"articleSection\":[\"Arrays\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/\",\"name\":\"Finding SubArray with Given Sum\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg\",\"datePublished\":\"2023-01-19T10:11:42+00:00\",\"dateModified\":\"2023-09-22T07:55:30+00:00\",\"description\":\"Understanding what SubArray is and learning about how to find subarray with given sum using different approaches.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arrays\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/arrays\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Finding SubArray with Given Sum\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Finding SubArray with Given Sum","description":"Understanding what SubArray is and learning about how to find subarray with given sum using different approaches.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/","og_locale":"en_US","og_type":"article","og_title":"Finding SubArray with Given Sum","og_description":"Understanding what SubArray is and learning about how to find subarray with given sum using different approaches.","og_url":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2023-01-19T10:11:42+00:00","article_modified_time":"2023-09-22T07:55:30+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Finding SubArray with Given Sum","datePublished":"2023-01-19T10:11:42+00:00","dateModified":"2023-09-22T07:55:30+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/"},"wordCount":881,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg","articleSection":["Arrays"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/","url":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/","name":"Finding SubArray with Given Sum","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg","datePublished":"2023-01-19T10:11:42+00:00","dateModified":"2023-09-22T07:55:30+00:00","description":"Understanding what SubArray is and learning about how to find subarray with given sum using different approaches.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674109358999-SubArray%20with%20Given%20Sum.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/subarray-with-given-sum\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Arrays","item":"https:\/\/prepbytes.com\/blog\/category\/arrays\/"},{"@type":"ListItem","position":3,"name":"Finding SubArray with Given Sum"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=11871"}],"version-history":[{"count":4,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11871\/revisions"}],"predecessor-version":[{"id":17977,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11871\/revisions\/17977"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=11871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=11871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=11871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}