<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by HARDIK CHUGH on Medium]]></title>
        <description><![CDATA[Stories by HARDIK CHUGH on Medium]]></description>
        <link>https://medium.com/@chughhardik?source=rss-2634ea1b31d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*a3qhXU8zT77lTfnfn90xCg.jpeg</url>
            <title>Stories by HARDIK CHUGH on Medium</title>
            <link>https://medium.com/@chughhardik?source=rss-2634ea1b31d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 19:57:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chughhardik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Redis — Installation and Explanation with Examples]]></title>
            <link>https://medium.com/@chughhardik/redis-installation-and-explanation-with-examples-91f9b0cb9f1c?source=rss-2634ea1b31d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/91f9b0cb9f1c</guid>
            <category><![CDATA[redis-introduction]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[redis-examples]]></category>
            <category><![CDATA[redis-explanation]]></category>
            <dc:creator><![CDATA[HARDIK CHUGH]]></dc:creator>
            <pubDate>Tue, 27 Aug 2019 16:47:31 GMT</pubDate>
            <atom:updated>2019-08-27T16:49:04.031Z</atom:updated>
            <content:encoded><![CDATA[<h3>Redis — Installation and Explanation with Examples</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLkERCK97XPxh3ZMge5qwQ.png" /><figcaption><strong>Redis — Installation and Understanding at Command Line</strong></figcaption></figure><p><a href="https://redis.io/">Redis</a><strong>( Remote Dictionary Server) </strong>is an open source <strong>in memory data structure store</strong> i.e data is stored in main memory rather than being stored in some database. It can be used as a cache, database(NOSQL) and message broker, but in most cases it’s used as cache.</p><p>It stores data in the form of <strong>key value</strong> pairs.Data Structures supported by Redis are as follows:</p><ol><li><strong>Strings</strong></li><li><strong>Hashes</strong></li><li><strong>Lists</strong></li><li><strong>Sets</strong></li><li><strong>Sorted Sets</strong></li><li><strong>Bitmaps</strong></li><li><strong>Hyperloglogs</strong></li><li><strong>Geospatial Indexes</strong></li></ol><blockquote>But primarily we use Strings, Hashes,Lists,Sets and Sorted Sets.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*88LJIfBZLpswtRtRso1JJA.png" /><figcaption><strong>Languages which can be used with redis</strong></figcaption></figure><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*lI3jk9H6G8ynKRY-u5JTrw.png" /><figcaption><strong>Twitter uses Redis for showing Timeline on users Feed</strong></figcaption></figure><blockquote><a href="http://highscalability.com/blog/2014/9/8/how-twitter-uses-redis-to-scale-105tb-ram-39mm-qps-10000-ins.html">Twitter</a> drives its <strong>timeline</strong> service with the help of Redis. Timeline is an list of tweets which are indexed by an id. Chaining tweets together in a list produces the Home timeline.</blockquote><h3><strong>Installation</strong></h3><p>To install redis on mac os, follow these steps:</p><pre>brew install redis</pre><p>Now we need to start the redis server, which can be done by:</p><pre>brew services start redis</pre><p>If anytime you want to stop redis server , we can do that by:</p><pre>brew services stop redis</pre><p>Now in order to check whether redis server is working or not:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*Mxt7Mgv2TiwuUdj6orDf5A.png" /><figcaption><strong>Redis server Working</strong></figcaption></figure><h3>Understanding Redis at Command Line</h3><p>We can enter redis-cli with the help of following command:</p><pre>redis-cli // Enter redis-cli to perform operations</pre><h3>1. Strings</h3><p><a href="https://redis.io/topics/data-types"><strong>Strings</strong></a> are the most basic kind of Redis value. Redis Strings are binary safe, this means that a Redis string can contain any kind of data, for instance a JPEG image or a serialized Ruby object.</p><p>A String value can be at max 512 Megabytes in length.</p><pre> SET age 29 // creating single Key value pairs</pre><pre> GET age //returns the value set for age</pre><pre> INCR age // Increments the age by 1</pre><pre> DECR age // Decrements the age by 1</pre><pre> MSET name &quot;Johny&quot; age &quot;23&quot; country &quot;India&quot; //creating multiple key value pairs </pre><pre> GET country // returns the value of country<br>  <br> EXPIRE age 10 // Expires value of age in 10 seconds</pre><figure><img alt="Strings Code Snippets -Redis" src="https://cdn-images-1.medium.com/max/533/1*7sZ07Wmx9lZtEIRuO66MYQ.png" /><figcaption><strong>String Data Structure</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*6dsIr1IL51CLeadWS4TF7w.png" /></figure><h3>2. Lists</h3><p><a href="https://redis.io/topics/data-types"><strong>Redis</strong> <strong>Lists</strong></a> are simply lists of strings, sorted by insertion order.We can add elements to Redis lists on the head (on the left) or on the tail (on the right) of the list.</p><pre>LPUSH people “John” // pushes value of people from left of List</pre><pre>LRANGE people 0 -1 // Returns all the values in list </pre><pre>RPUSH people &quot;Karry&quot; // Pushes value of people from right side of List</pre><pre>LLEN people // Returns length of the list</pre><pre>LPOP people // Pops up value from left of the list</pre><pre>RPOP people // Pops up value from Right of the list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*ojJ3vLHVGCZAVXC7I9wCrw.png" /><figcaption><strong>List Data Structure</strong></figcaption></figure><h3>3. Sets</h3><p><a href="https://redis.io/topics/data-types"><strong>Redis Sets</strong></a> are an unordered collection of Strings. It is possible to add, remove, and test for existence of members in O(1).Redis Sets have the desirable property of not allowing repeated members. Adding the same element multiple times will result in a set having a single copy of this element.</p><pre>SADD languages “Java” // adds memebers to set stored at key</pre><pre>SMEMBERS languages // returns all the elements of the sets</pre><pre>SISMEMBER languages &quot;Java&quot; // returns 1 if that element is present in set else returns 0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*zGWDY_HdlMASs4fnXMvz_w.png" /><figcaption><strong>Sets Data Structure</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*swZKY2TdiJzLyNKZTOwCZQ.png" /></figure><h3>4. Sorted Sets</h3><p><a href="https://redis.io/topics/data-types"><strong>Redis</strong> <strong>Sorted Sets</strong></a> are, similarly to Redis Sets, non repeating collections of Strings. The difference is that every member of a Sorted Set is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score.</p><pre>ZADD items 5000 “Hard-drive”</pre><pre>ZRANK items &quot;Mouse&quot; // returns the rank of set as per ascending order</pre><pre>ZRANGE items 0 -1 // returns all the items in the set in ascending order</pre><pre>ZINCRBY items 3 &quot;Mouse&quot; // increments the value for set mouse by 3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*kQGegXihxzvwCUuuoLCdag.png" /><figcaption><strong>Sorted Sets Data Structure</strong></figcaption></figure><blockquote>I hope this gives pretty decent overview to start with <strong>Redis. </strong>To learn more about Redis checkout: <a href="https://redis.io/">https://redis.io/</a></blockquote><p>Cheers!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91f9b0cb9f1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Google Analytics with your Web apps]]></title>
            <link>https://medium.com/@chughhardik/integrating-google-analytics-with-your-web-apps-d92d44c108f3?source=rss-2634ea1b31d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d92d44c108f3</guid>
            <category><![CDATA[analytics-js]]></category>
            <category><![CDATA[google-analytics]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[gtag-js]]></category>
            <dc:creator><![CDATA[HARDIK CHUGH]]></dc:creator>
            <pubDate>Sat, 20 Jul 2019 17:30:20 GMT</pubDate>
            <atom:updated>2019-07-20T17:32:50.395Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JFXX19Mi7VdDpqhhPm9Gjg.png" /><figcaption><strong>Google Analytics</strong></figcaption></figure><p>As a Developer or owner of website we want to know who your audience is, what part of the website they are spending the most time on, what is their Geographic location, what is the age group and much more.</p><p>So to achieve this goal there are many products in the market right now like Google Analytics, Facebook Analytics and many more.Here we will be getting to know about the Google Analytics.</p><p><strong>Let’s get Started:</strong></p><p>We have two ways to integrate Google Analytics -</p><ol><li><strong>analytics.js: </strong>The <a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/"><em>analytics.js</em></a> library is a JavaScript library for measuring how users interact with your website.</li><li><strong>gtag.js:</strong> The <a href="https://developers.google.com/analytics/devguides/collection/gtagjs/"><em>global site tag (gtag.js)</em></a> is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform.</li></ol><p>You can use any of the two, their implementation is almost similar.Here I will be implementing using <strong>gtag.js, </strong>you can use any one of them<strong>.</strong></p><h3>Step 1:</h3><p>You have to go at <a href="https://analytics.google.com/">https://analytics.google.com/</a> and Sign up. Once you click on Sign up button you will see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5eKUYRcopZ15uLm06AUPZw.png" /><figcaption><strong>Creating a new account for getting your Tracking ID</strong></figcaption></figure><p>Once you fill all details, you will be redirected to page where you can see your Tracking ID.</p><p>Your Tracking ID would be something like this-</p><p><strong>UA-5919488233–7</strong></p><h3>Step 2:</h3><p>You have to include this script inside your html file where you want to integrate Google Analytics.</p><pre>&lt;script async src=”https://www.googletagmanager.com/gtag/js?id=&lt;Your Tracking ID&gt;&quot;&gt;&lt;/script&gt;</pre><pre>&lt;script&gt;</pre><pre>window.dataLayer = window.dataLayer || [];</pre><pre>function gtag(){dataLayer.push(arguments);}</pre><pre>gtag(‘js’, new Date());</pre><pre>gtag(‘config’, ‘&lt; Your Tracking  &gt;’);</pre><pre>&lt;/script&gt;</pre><p>By adding this script to the web page you want to monitor, you can check how many times a webpage has been visited. In order to check analytics visit-<a href="https://analytics.google.com/analytics/web/#/">https://analytics.google.com/analytics/web/</a></p><p>On Visiting this link you will see your <strong>Dashboard </strong>which would look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKJmmolxuwsMSEsaPWJlBQ.png" /><figcaption><strong>Google Analytics Dashboard</strong></figcaption></figure><p>Now when user visits your website and visits pages where you have added analytics you will see the changes in your Dashboard.</p><p>Now if you want to track User movement on your web app you can do that by adding <strong>Event Tracking</strong> to your web app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fe1tkINDyMY_Dsa_BVUqwg.png" /><figcaption><strong>Event Tracking For Google Analytics</strong></figcaption></figure><p><strong>For eg:</strong> Here you want to track how many users are clicking<strong> Publish </strong>button and you want to keep track of them, so we need to follow intent something like this:</p><pre>gtag(&#39;event&#39;, &lt;action&gt;, {<br>  &#39;event_category&#39;: &lt;category&gt;,<br>  &#39;event_label&#39;: &lt;label&gt;,<br>  &#39;value&#39;: &lt;value&gt;<br>});</pre><p>We need to add this code alongside the event listener we need to use. So here we will be<strong> onclick </strong>event listener to track how many times publish button has been clicked.</p><p><strong>Note: All the above values are completely customisable you can add them as per your choice and they may vary from person to person</strong>.</p><pre>&lt;input type=”submit” value=”Publish” onclick=”gtag(&#39;event&#39;,&#39;Publishing Post&#39;,{ &#39;event_category&#39; : &#39;Publish &#39;,  &#39;event_label&#39; : &#39;User Clicks Publish button&#39; ” /&gt;</pre><p>Now When user clicks on this button a trigger will be made to Google Analytics Dashboard and you can view that on your Dashboard that user clicked this button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mr1sdyFsnQjcJ20QERzCnQ.png" /><figcaption><strong>Event Tracking For Analytics Dashboard</strong></figcaption></figure><p>You can add any event listener you want and you can view them under -</p><h3><strong>Behavior -&gt; Events -&gt; Overview</strong></h3><p>Hope you liked it, if you do then give some claps to it!!!!</p><p>Cheers!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d92d44c108f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Truecaller Login to your Web app]]></title>
            <link>https://medium.com/@chughhardik/adding-truecaller-login-to-your-web-app-5e15e2c14ad0?source=rss-2634ea1b31d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e15e2c14ad0</guid>
            <category><![CDATA[truecaller-sdk]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[truecaller]]></category>
            <category><![CDATA[truecaller-mweb]]></category>
            <category><![CDATA[mobile-web]]></category>
            <dc:creator><![CDATA[HARDIK CHUGH]]></dc:creator>
            <pubDate>Wed, 26 Jun 2019 18:31:53 GMT</pubDate>
            <atom:updated>2020-07-13T10:18:02.040Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are looking for options to make it easier for your new or current users to sign up/ sign in, then <a href="https://developer.truecaller.com/">Truecaller Mobile web SDK</a> is probably one of the best options available in market right now.</p><p>It’s very simple to integrate it into your web apps. Initially, you will need to generate App key which is unique for every web app you want to integrate Truecaller m-web SDK, so to <a href="https://developer.truecaller.com/sign-up">generate unique Key</a>, go through this link.</p><p>Once you sign up you can view this screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eF0cuqciGxLf-UXorXuTZQ.jpeg" /><figcaption><strong>Generating your Unique App Key</strong></figcaption></figure><p><strong>POINTS TO BE CONSIDERED WHILE CREATING APP KEY</strong></p><ol><li>Select web from the options given there</li><li>In <strong>App domain </strong>you have to URL of your web app, something like this <strong>https://www.mysampleapp.com/ . </strong>Note <strong>HTTP</strong> protocol is not supported.</li><li>In <strong>Callback url </strong>you<strong> </strong>have to add url where your <strong>access token </strong>will be sent as <strong>POST</strong> request. <strong>For eg</strong>: On your Backend you want to receive access token on <strong>/auth/token , </strong>then considering the above example your callback url will be <strong>https://www.mysampleapp.com/auth/token</strong></li></ol><p>Now, once you complete the above steps, your app key will be created and your dashboard will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axB3WDRW2sbqcvE_D_AvMQ.jpeg" /><figcaption><strong>Developers Dashboard for managing Apps integrated with Truecaller m-web SDK</strong></figcaption></figure><p>Now in order to invoke <a href="https://truecaller4developers.gitbook.io/truecallersdk/mobile-websites/integrating-with-your-mobile-website/initialisation"><strong>Deep Link </strong>into your web app</a> you need to add this to your code in <strong>Client</strong> side:</p><pre>let req_nonce = 123456789598;  // random number of length 8 to 64 characters</pre><pre>window.location = `truecallersdk://truesdk/web_verify?requestNonce=${req_nonce}&amp;partnerKey=YOUR_APP_KEY&amp;partnerName=YOUR_APP_NAME&amp;lang=LANGUAGE_LOCALE&amp;title=TITLE_STRING_OPTION&amp;skipOption=FOOTER_CTA_STRING`;</pre><pre>}, 600);</pre><p>Now after this your Deep link will be invoked and your screen will be look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*blD8ttuCZK5gjuRiLzgY3g.jpeg" /></figure><p>Now Once user clicks on <strong>CONTINUE </strong>button a <strong>token</strong> will be sent as <strong>POST request </strong>to the url which you set in the <strong>Callback URL</strong> in while generating unique key for your app something like this:</p><p><strong>{“requestId”:”123456789598=”,”accessToken”:”a1asX — 8_yw-OF — E6Gj_DPyKelJIGUUeYB9U9MJhyeu4hOCbrl”,”endpoint”:&quot;https://profile4-noneu.truecaller.com/v1/default&quot;}</strong></p><blockquote>After doing all this if you are not sure whether you are receiving data or not on the callback url, you can go to this link where you will see a unique url on your screen, then what you can do is create a new app and in that app set <strong>callback url </strong>as the <strong>unique url</strong> which you just which you saw, and then assign <strong>partner key </strong>to that key which you just generated. Now after saving all this, when you click on <strong>CONTINUE </strong>button and if you <a href="https://webhook.site/">go here</a> you can see that you have received your access token with request ID as mentioned above.</blockquote><p>As Now, we are receiving <strong>access Token</strong> and <strong>request ID</strong> along with endpoint, so now we need to make<strong> GET</strong> request to this endpoint along with our <strong>access Token</strong> as params. For this example we will be using <a href="https://github.com/request/request"><strong>request</strong></a> to do our this API call and you can use anyone with which you feel comfortable :</p><p>You need to do all this thing in the callback url where you received your access Token.</p><p>Now your code on backend would look something like this:</p><pre>const options = {<br>  method: &quot;GET&quot;,<br>  url: &quot;https://profile4.truecaller.com/v1/default&quot;,<br>  headers: { Authorization: `Bearer ${req.body.accessToken}` },<br>  json: true<br>};<br>request(options, function(error, response, body) {<br>  <br>     // Add your code here<br>     // In this you will receive data when users clicks on <strong>Continue</strong> </pre><pre>});</pre><p>Now as you are receiving user data, you can now implement <strong>Polling</strong> or <strong>Sockets</strong> logic to display user data.</p><p><strong>Polling: </strong>In this we send request to the server again and again after fixed intervals of time. For eg: You want to send <strong>GET</strong> request to your backend every <strong>n seconds</strong> for <strong>n intervals</strong> and as soon as it receives data it stops sending requests any further.</p><p>Now in your files having <strong>Client side</strong> code, you can add this:</p><pre>setTimeout(function() {<br><br>  if( document.hasFocus() ){</pre><pre>    // To Check whether Truecaller App is present on device or not<br>    // You can add your logic here    <br> <br>  }<br>  else{<br>    // Truecaller app present on the device and the profile overlay opens<br>    // The user clicks on verify &amp; you&#39;ll receive the user&#39;s access token to fetch the profile on your <br>    // callback URL - post which, you can refresh the session at your frontend and complete the user  verification<br>  }<br>}, 600);</pre><p>After doing all these steps your integration will be working fine.</p><p><strong>Cheers!!!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e15e2c14ad0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Problem To Find Area of Largest Rectangle Using Stack]]></title>
            <link>https://medium.com/@chughhardik/problem-to-find-area-of-largest-rectangle-using-stack-463a21f8f0f9?source=rss-2634ea1b31d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/463a21f8f0f9</guid>
            <category><![CDATA[stack]]></category>
            <category><![CDATA[c-language]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[stl]]></category>
            <dc:creator><![CDATA[HARDIK CHUGH]]></dc:creator>
            <pubDate>Mon, 17 Sep 2018 07:05:44 GMT</pubDate>
            <atom:updated>2018-09-17T07:05:44.004Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a Common problem to find Area of Largest Rectangle.There are many methods to solve the problem but this time we are solving using <strong>Stack.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/183/1*DmtxfGy9K9PZbFeW2txXCQ.png" /><figcaption>Area of Largest Rectangle Formed</figcaption></figure><p>To Solve this problem, initially we need to understand that we consider the following rectangle to have largest area which obeys following conditions-</p><p><strong>. Has Been Stretched to maximum blocks and that particular height is there among those Blocks.</strong></p><p>In the given example above, we considered the highlighted area because <strong>height of 4</strong> is common among those 3 rectangles simultaneously. <strong>Area=width*Height</strong>, (3*4=12)</p><p>Below is the method explained in C++ using stacks-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*CLr0jBpjHGeH2cZc3O3Rzw.png" /><figcaption>Area of Largest Rectangle Calculated using Stack</figcaption></figure><p>We have taken arguments of the function in Vectors form and later on we will store the required values in stack.</p><p>Initially, the stack is empty, to insert the value into stack we check if <strong>stack is empty</strong> or value of current position of iterator ‘i’ at vector ‘h’ should be greater than value at the top of stack. If any of the above condition is satisfied then that particular element is inserted into stack and iterator is incremented by 1.</p><p>If the above two conditions are not fulfilled then we move to else part in our while loop. We store the reference of top element in stack in a variable ‘m’ and then <strong>pop</strong> the top element of stack. After that we will check, if <strong>stack is empty</strong> then we will <strong>multiply</strong> current position of iterator with vector at position ‘m’ ,which we used earlier and store that value in variable named ‘area’.Initially value of ‘max_area’ is 0, if value of ‘max_area’ is less than ‘area’ then we will assign value of ‘area’ to ‘max_area’ so that ‘max_area’ only contains <strong>maximum</strong> value at a point of time, and this process goes on until the loop stops.</p><p>After that,same operation is performed is on elements stored in stack and get the calculate the value of ‘max_area’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*p0rUnnVBBVhdHwVgjixv8w.png" /><figcaption>Result contains the value returned from the function</figcaption></figure><p><strong>STEP BY STEP EXPLANATION OF GIVEN EXAMPLE:</strong></p><ol><li><strong>Initially value of i is 0 , also as stack is empty,then first element of vector which is 6 is inserted into stack, and ‘i’ is incremented by 1.</strong></li><li><strong>Loop is iterated again and again if condition is checked , as value at top of stack is greater than current position of element in vector,so it moves to else part in the loop. We store the reference to top element of stack in variable ‘m’ and then pop the top element of stack. As stack is not empty then (i-s.top()-1) condition is evaluated and multiplied with element of vector at current position of iterator and stored in variable ‘area’. After that if condition is evaluated and as value of ‘max_area’ is less than ‘area’, so value of ‘area’ is stored in ‘max_area’ . In this case value of ‘area’ comes to be 6 , so for this instance value of ‘max_area’ is 6 .</strong></li><li><strong>And the process goes on and on till the loop exits.</strong></li><li>In the coming sequence value of <strong>‘area</strong>’ comes to be — <strong>5 , 5 , 12, 10</strong> respectively.</li><li>Similar operations are performed on elements of stack, and we need to get the maximum value of area in ‘<strong>max_area</strong>’.</li><li>After performing operations on this elements of stack we get the following values of ‘<strong>area</strong>’ in this case — <strong>6,7 .</strong></li><li>As all these values are less than ‘<strong>max_area</strong>’ , so we won’t be using these values in this example.</li><li>At the end, we will return the ‘<strong>max_area</strong>’ .</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=463a21f8f0f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>