{"id":9614,"date":"2022-09-12T09:23:56","date_gmt":"2022-09-12T09:23:56","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=9614"},"modified":"2022-10-03T04:00:08","modified_gmt":"2022-10-03T04:00:08","slug":"count-subarrays-where-second-highest-lies-before-highest","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/","title":{"rendered":"Count Subarrays where Second Highest lies before Highest"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg\" alt=\"\" \/><\/p>\n<h3>Problem Statement<\/h3>\n<p>You will be given an array of N distinct elements. The minimum value of N is 2. In every subarray of the given <a href=\"https:\/\/prepbytes.com\/blog\/tag\/arrays\/\" title=\"array\">array<\/a>, you have to find such pairs (x,y), where x is the index of the second largest element of the subarray, and y is the index of the largest element of the subarray such that x &lt; y. Your task is to return the total number of such distinct pairs in an array.<\/p>\n<p><strong>Example<\/strong><\/p>\n<p>Let us consider the array and its subarrays shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662972700331-6-01.png\" alt=\"\" \/><\/p>\n<p>Now, for the second highest and highest to exist, the size of the subarray should at least be 2. So, the subarrays {4}, {6}, {5} and {7} have 0 such pairs.<\/p>\n<p>Now, in the subarray {4,6}, we have the second highest at index 1 and highest element at index 2 (1-based indexing). Also, the index of the second highest element is less than that of the highest element. Hence, we have found a valid pair.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662972777421-6-02.png\" alt=\"\" \/><\/p>\n<p>Now, for the subarray {6,5}, the index of the second largest element is greater than the index of the largest element. Hence, no valid pair is found here.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662972909279-6-03.png\" alt=\"\" \/><\/p>\n<p>For the subarray {5,7}, the valid pair is {1,2}. Since we already have that pair from the subarray {4,6}, we won\u2019t consider it as we want distinct pairs.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662972947894-6-04.png\" alt=\"\" \/><\/p>\n<p>Now, the subarray {4,6,5} has the second highest element at index 3 and the highest at index 2 which does not follow x &lt; y, hence it has 0 valid pairs.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662972028104-6-05.png\" alt=\"\" \/><\/p>\n<p>In the subarray {6,5,7}, the index of the second highest element is 2 and the index of the highest element is 3. So, we have a valid pair {1,3}.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973026116-6-06.png\" alt=\"\" \/><\/p>\n<p>Finally, from the entire array, the index of the second largest element is 2 and the index of the largest element is 4. So, we have a valid pair {2,4}. Hence, we have 3 valid pairs. So, the count is 3.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973079858-6-07.png\" alt=\"\" \/><\/p>\n<h3>Brute Force Approach (Intuition)<\/h3>\n<p>We know the brute force approach will be to generate all the subarray and maintain the pairs with us. So, in each subarray, we find the index of the largest and the second largest element and try to see if the pair exists or not. If it is a valid pair that does not exist, consider that pair, else leave it. The time complexity of this approach will be O(N2) and space complexity will be O(P) where P is the number of valid pairs.<\/p>\n<h3>Approach (Using Stack)<\/h3>\n<p>So, we know that the brute force approach is quadratic in time complexity. We can however solve this problem in linear time complexity as well. We can use the concept of Next Greater Element (NGE).<\/p>\n<p>Let us consider an array shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973333343-6-08.png\" alt=\"\" \/><\/p>\n<p>Let us say the current index at which we are is index 4. <\/p>\n<p>Let us say that prev is the index of the Next Greater Element (NGE) to the left of current. So, prev = 1. Also, let us say that next is the index of the NGE towards the right of the current index. So, next = 6.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973253117-6-09.png\" alt=\"\" \/><\/p>\n<p>Now, observe that all the subarrays with starting index in the range [prev + 1, z] (both inclusive) and ending at index \u201cnext\u201d, have the second largest element at index = curr and the largest element at index = next.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973436374-6-10.png\" alt=\"\" \/><\/p>\n<p>We can also observe that there are (curr &#8211; prev) valid pairs in these subarrays.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973477452-6-11.png\" alt=\"\" \/><\/p>\n<p>So, this means that we just have to know the NGE to the left and right of each index and then add curr &#8211; prev for all the indices to get the total number of valid pairs.<\/p>\n<p>Now, the only thing which remains is to discuss how to calculate NGE to the right and left. So, let us discuss the same.<\/p>\n<p><strong><em>Note:<\/em><\/strong> In further discussion, the L array is the array that contains NGE to left, and the R array is the array that contains NGE to the right.<\/p>\n<h3>Next Greater Element (NGE) to the Left<\/h3>\n<p>Consider the array shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973503210-6-12.png\" alt=\"\" \/><\/p>\n<p>So, we have an empty L array that we have to fill. Let us take a Stack and let us take a pointer at index 0 as shown below. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973561383-6-13.png\" alt=\"\" \/><\/p>\n<p>For index 0, there is no element to the left. Hence, there will not be any NGE to the left. So, L[0] = 0, and we push the index 0 into the stack.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973587488-6-14.png\" alt=\"\" \/><\/p>\n<p>Now, array[i] = array[1] = 8 is less than array[top of stack]. So, the top of the stack will become the next greater element (NGE) to the left for index 1. Hence, L[1] = 0.   <\/p>\n<p>However, in the question, since we are given 1-based indexing, L[1] = top of stack + 1. Hence, L[1] = 0+1 = 1.<\/p>\n<p>We will also push the current index into the stack because the element at our index can be an NGE for some other index moving forward.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973678748-6-15.png\" alt=\"\" \/><\/p>\n<p>So, we can establish the following conclusion from above.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973630179-6-16.png\" alt=\"\" \/><\/p>\n<p>So, using this conclusion, we can fill our answers till index 3 as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973706509-6-17.png\" alt=\"\" \/><\/p>\n<p>Now, at index 4, arr[i] &gt; arr[top]. So, we have to pop from the stack till the stack is not empty and arr[i] &gt; arr[top].<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973737824-6-18.png\" alt=\"\" \/><\/p>\n<p>So, after popping the elements from the stack, the next step is same as above.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973774000-6-19.png\" alt=\"\" \/><\/p>\n<p>So, the conclusion that we derive from here is shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973809511-6-20.png\" alt=\"\" \/><\/p>\n<p>One thing is left to discuss. What if we keep popping from the stack and it becomes empty? Consider the case when i moves to the next index i.e. index 5.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973857966-6-21.png\" alt=\"\" \/><\/p>\n<p>In this case, value at index 5 is greater than all the other values. So, the stack becomes empty. In this case, stack being empty means that there is no NGE to the left. Hence, L[i] = 0. Also, we will push the current index into the stack.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662973916152-6-22.png\" alt=\"\" \/><\/p>\n<p>So, the conclusion derived from here is shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974004328-6-23.png\" alt=\"\" \/><\/p>\n<p>Now, try filling the last index of L array yourself. It is as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974086529-6-24.png\" alt=\"\" \/><\/p>\n<p>So, we have completely filled the L array. Now, we have to fill the R array. Let us discuss it.<\/p>\n<p>Next Greater Element (NGE) to the Right<\/p>\n<p>This process is a little bit different from the previous one. Here, let us assume that we have once filled the array with all 0s and have already pushed the 0 index into the stack as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974131332-6-25.png\" alt=\"\" \/><\/p>\n<p>We start iterating from index 1. Since arr[i] = arr[1] = 8 &lt; arr[top], i cannot be the NGE index for the top of the stack i.e. index 0. However, it can be an NGE index for some other index moving forward. Hence, we will push it into the stack.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974180392-6-26.png\" alt=\"\" \/><\/p>\n<p>The conclusion that we devise from here is given below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974454331-6-28.png\" alt=\"\" \/><\/p>\n<p>So, with this conclusion, we will move till index 3 and no change will take place in the R array.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974235633-6-27.png\" alt=\"\" \/><\/p>\n<p>Now, arr[i] = arr[4] = 4 is greater than arr[top] = arr[3] = 3. So, i=4 will be the NGE index for the top of the stack. Hence, we pop it from the stack, and R[top] = i + 1. We have done plus 1 because the indices in the question are 1-based.<\/p>\n<p>Also, we will do this till the stack is not empty and arr[i] &gt; arr[top].<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974378450-6-29.png\" alt=\"\" \/><\/p>\n<p>The conclusion that we draw from here is shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974339835-6-30.png\" alt=\"\" \/><\/p>\n<p>So, when we are at index = 5, we can see this better as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974569841-6-31.png\" alt=\"\" \/><\/p>\n<p>Finally, the R array gets completely filled.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974533049-6-32.png\" alt=\"\" \/><\/p>\n<p>So, we have learned the Next Greater Element to the Right.<br \/>\nSo, now that we have understood the complete procedure, let us write the code for the same.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_9637 {\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_9637 .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_9637 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_9637 .wpsm_nav-tabs > li.active > a, #tab_container_9637 .wpsm_nav-tabs > li.active > a:hover, #tab_container_9637 .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_9637 .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_9637 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_9637 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_9637 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_9637 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_9637 .wpsm_nav-tabs > li > a:hover , #tab_container_9637 .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_9637 .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_9637 .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_9637 .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_9637 .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_9637 .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_9637 .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_9637 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_9637 .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_9637 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_9637 .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_9637 .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_9637\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_9637\">\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_9637_1\" aria-controls=\"tabs_desc_9637_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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_9637_2\" aria-controls=\"tabs_desc_9637_2\" 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>Java<\/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_9637\">\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_9637_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include <bits\/stdc++.h>\r\n#define MAXN 100005\r\nusing namespace std;\r\n\r\nvoid NGE_To_Right(int arr[], int n, int nextBig[])\r\n{\r\n\tstack<pair<int, int> > s;\r\n\r\n\tfor (int i = n - 1; i >= 0; i--) {\r\n\r\n\t\tnextBig[i] = i;\r\n\t\twhile (!s.empty() && s.top().first < arr[i])\r\n\t\t\ts.pop();\r\n\r\n\t\tif (!s.empty())\r\n\t\t\tnextBig[i] = s.top().second;\r\n\r\n\t\ts.push(pair<int, int>(arr[i], i));\r\n\t}\r\n}\r\n\r\nvoid NGE_To_Left(int arr[], int n, int prevBig[])\r\n{\r\n\tstack<pair<int, int> > s;\r\n\tfor (int i = 0; i < n; i++) {\r\n\r\n\t\tprevBig[i] = -1;\r\n\t\twhile (!s.empty() && s.top().first < arr[i])\r\n\t\t\ts.pop();\r\n\r\n\t\tif (!s.empty())\r\n\t\t\tprevBig[i] = s.top().second;\r\n\r\n\t\ts.push(pair<int, int>(arr[i], i));\r\n\t}\r\n}\r\n\r\nint count_valid_pairs(int arr[], int n)\r\n{\r\n\tint nextBig[MAXN];\r\n\tint prevBig[MAXN];\r\n\tint maxi[MAXN];\r\n\tint ans = 0;\r\n\r\n\tNGE_To_Left(arr, n, prevBig);\r\n\r\n\tNGE_To_Right(arr, n, nextBig);\r\n\r\n\tfor (int i = 0; i < n; i++)\r\n\t\tif (nextBig[i] != i)\r\n\t\t\tmaxi[nextBig[i] - i] = max(maxi[nextBig[i] - i],i - prevBig[i]);\r\n\r\n\tfor (int i = 0; i < n; i++)\r\n\t\tans += maxi[i];\r\n\r\n\treturn ans;\r\n}\r\n\r\nint main()\r\n{\r\n\tint arr[] = {4,6,5,7};\r\n\tint n = sizeof(arr) \/ sizeof(arr[0]);\r\n\tcout << count_valid_pairs(arr, n) << endl;\r\n\treturn 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_9637_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nimport java.util.*;\r\n\r\npublic class Main\r\n{\r\n\t\r\n    static int MAXN = 100005;\r\n    \r\n    static class pair\r\n    {\r\n    \tint first, second;\r\n    \tpublic pair(int first, int second)\r\n    \t{\r\n    \t\tthis.first = first;\r\n    \t\tthis.second = second;\r\n    \t}\r\n    }\r\n    \r\n    static void NGEToRight(int arr[], int n, int nextBig[])\r\n    {\r\n    \tStack<pair> s = new Stack<>();\r\n    \r\n    \tfor (int i = n - 1; i >= 0; i--)\r\n    \t{\r\n    \r\n    \t\tnextBig[i] = i;\r\n    \t\twhile (!s.empty() && s.peek().first < arr[i])\r\n    \t\t\ts.pop();\r\n    \r\n    \t\tif (!s.empty())\r\n    \t\t\tnextBig[i] = s.peek().second;\r\n    \r\n    \t\ts.push(new pair(arr[i], i));\r\n    \t}\r\n    }\r\n    \r\n    static void NGEToLeft(int arr[], int n, int prevBig[])\r\n    {\r\n    \tStack<pair> s = new Stack<>();\r\n    \tfor (int i = 0; i < n; i++)\r\n    \t{\r\n    \r\n    \t\tprevBig[i] = -1;\r\n    \t\twhile (!s.empty() && s.peek().first < arr[i])\r\n    \t\t\ts.pop();\r\n    \r\n    \t\tif (!s.empty())\r\n    \t\t\tprevBig[i] = s.peek().second;\r\n    \r\n    \t\ts.push(new pair(arr[i], i));\r\n    \t}\r\n    }\r\n    \r\n    static int countValidPairs(int arr[], int n)\r\n    {\r\n    \tint []nextBig = new int[MAXN];\r\n    \tint []prevBig = new int[MAXN];\r\n    \tint []maxi = new int[MAXN];\r\n    \tint ans = 0;\r\n    \r\n    \tNGEToLeft(arr, n, prevBig);\r\n    \r\n    \tNGEToRight(arr, n, nextBig);\r\n    \r\n    \tfor (int i = 0; i < n; i++)\r\n    \t\tif (nextBig[i] != i)\r\n    \t\t\tmaxi[nextBig[i] - i] = Math.max(maxi[nextBig[i] - i],i - prevBig[i]);\r\n    \r\n    \tfor (int i = 0; i < n; i++)\r\n    \t\tans += maxi[i];\r\n    \r\n    \treturn ans;\r\n    }\r\n    \r\n    \r\n    public static void main(String[] args)\r\n    {\r\n    \r\n    \tint arr[] = {4,6,5,7};\r\n    \tint n = arr.length;\r\n    \r\n    \tSystem.out.println(countValidPairs(arr, n));\r\n    }\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\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_9637 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_9637 a\"),jQuery(\"#tab-content_9637\"));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>Time Complexity<\/strong><\/p>\n<p>The time complexity for this algorithm is O(N). This is because we are calculating the NGE towards left and right which takes O(N) time each. Then, we are simply traversing the entire array to add all the values up.<\/p>\n<p><strong>Space Complexity<\/strong><\/p>\n<p>The space complexity is O(N) as we use two arrays for having the NGEs to the left and right.<\/p>\n<p>This article tried to discuss How to Count Subarrays where Second Highest lies before Highest. Hope this blog helps you understand and solve the problem. To practice more problems you can check out <a href=\"#\" title=\"\"><\/a> at <a href=\"https:\/\/www.prepbytes.com\/\" title=\"Prepbytes\">Prepbytes<\/a>.<br \/>\n.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Statement You will be given an array of N distinct elements. The minimum value of N is 2. In every subarray of the given array, you have to find such pairs (x,y), where x is the index of the second largest element of the subarray, and y is the index of the largest element [&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-9614","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>Count Subarrays where Second Highest lies before Highest<\/title>\n<meta name=\"description\" content=\"This article tried to discuss How to Count Subarrays where Second Highest lies before Highest. Hope this blog helps you understand and solve the problem.\" \/>\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\/count-subarrays-where-second-highest-lies-before-highest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Count Subarrays where Second Highest lies before Highest\" \/>\n<meta property=\"og:description\" content=\"This article tried to discuss How to Count Subarrays where Second Highest lies before Highest. Hope this blog helps you understand and solve the problem.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/\" \/>\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=\"2022-09-12T09:23:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-03T04:00:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.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=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Count Subarrays where Second Highest lies before Highest\",\"datePublished\":\"2022-09-12T09:23:56+00:00\",\"dateModified\":\"2022-10-03T04:00:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/\"},\"wordCount\":1319,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg\",\"articleSection\":[\"Arrays\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/\",\"name\":\"Count Subarrays where Second Highest lies before Highest\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg\",\"datePublished\":\"2022-09-12T09:23:56+00:00\",\"dateModified\":\"2022-10-03T04:00:08+00:00\",\"description\":\"This article tried to discuss How to Count Subarrays where Second Highest lies before Highest. Hope this blog helps you understand and solve the problem.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#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\":\"Count Subarrays where Second Highest lies before Highest\"}]},{\"@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":"Count Subarrays where Second Highest lies before Highest","description":"This article tried to discuss How to Count Subarrays where Second Highest lies before Highest. Hope this blog helps you understand and solve the problem.","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\/count-subarrays-where-second-highest-lies-before-highest\/","og_locale":"en_US","og_type":"article","og_title":"Count Subarrays where Second Highest lies before Highest","og_description":"This article tried to discuss How to Count Subarrays where Second Highest lies before Highest. Hope this blog helps you understand and solve the problem.","og_url":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-09-12T09:23:56+00:00","article_modified_time":"2022-10-03T04:00:08+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Count Subarrays where Second Highest lies before Highest","datePublished":"2022-09-12T09:23:56+00:00","dateModified":"2022-10-03T04:00:08+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/"},"wordCount":1319,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg","articleSection":["Arrays"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/","url":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/","name":"Count Subarrays where Second Highest lies before Highest","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg","datePublished":"2022-09-12T09:23:56+00:00","dateModified":"2022-10-03T04:00:08+00:00","description":"This article tried to discuss How to Count Subarrays where Second Highest lies before Highest. Hope this blog helps you understand and solve the problem.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1662974614109-6%20Topic.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/count-subarrays-where-second-highest-lies-before-highest\/#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":"Count Subarrays where Second Highest lies before Highest"}]},{"@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\/9614","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=9614"}],"version-history":[{"count":4,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/9614\/revisions"}],"predecessor-version":[{"id":9748,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/9614\/revisions\/9748"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=9614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=9614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=9614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}