<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rubleen Kaur</title>
    <description>The latest articles on DEV Community by Rubleen Kaur (@rubleen1903).</description>
    <link>https://dev.to/rubleen1903</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F610113%2Fe6470c18-18db-43ad-b54b-3242b0d33af6.jpeg</url>
      <title>DEV Community: Rubleen Kaur</title>
      <link>https://dev.to/rubleen1903</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rubleen1903"/>
    <language>en</language>
    <item>
      <title>Valid Mountain Array — Solution and Approch in Java</title>
      <dc:creator>Rubleen Kaur</dc:creator>
      <pubDate>Sat, 31 Jul 2021 12:59:48 +0000</pubDate>
      <link>https://dev.to/rubleen1903/valid-mountain-array-solution-and-approch-in-java-p6g</link>
      <guid>https://dev.to/rubleen1903/valid-mountain-array-solution-and-approch-in-java-p6g</guid>
      <description>&lt;p&gt;I have started practising for my interviews on Leetcode and thought of sharing each problem and the approach i use for solving them through these blogs.&lt;br&gt;
The first problem I chose is Valid Mountain Array and is an easy problem as compared to the one’s i’ve come across on leetcode.Each and every problem has an algorithmic approach one needs to understand before moving ahead with coding the solution.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The problem we are going to discuss : &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a href="https://leetcode.com/problems/valid-mountain-array/" rel="noopener noreferrer"&gt;Valid Mountain Array&lt;/a&gt;
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmsa2cd5o39euiea4n92z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmsa2cd5o39euiea4n92z.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Given an array of integers arr, return true if and only if it is a valid mountain array.&lt;br&gt;
Recall that arr is a mountain array if and only if:&lt;br&gt;
*&lt;code&gt;arr.length &amp;gt;= 3&lt;/code&gt;&lt;br&gt;
*There exists some i with 0 &amp;lt; i &amp;lt; arr.length - 1 such that:&lt;br&gt;
*&lt;code&gt;arr[0] &amp;lt; arr[1]&lt;/code&gt; &amp;lt; ... &amp;lt; &lt;code&gt;arr[i - 1] &amp;lt; arr[i]&lt;/code&gt;&lt;br&gt;
*&lt;code&gt;arr[i] &amp;gt; arr[i + 1]&lt;/code&gt; &amp;gt; ... &amp;gt; &lt;code&gt;arr[arr.length - 1]&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach :
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqc26lqap9c67thua5l7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqc26lqap9c67thua5l7.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I solved it using two variables which were used to check the given conditions.&lt;br&gt;
Do go through the above images to get a detailed approach and alogirthm how the problem was solved.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution in Java !
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 941. Valid Mountain Array
// Easy
// Given an array of integers arr, return true if and only if it is a valid mountain array.

// Recall that arr is a mountain array if and only if:

// arr.length &amp;gt;= 3
// There exists some i with 0 &amp;lt; i &amp;lt; arr.length - 1 such that:
// arr[0] &amp;lt; arr[1] &amp;lt; ... &amp;lt; arr[i - 1] &amp;lt; arr[i]
// arr[i] &amp;gt; arr[i + 1] &amp;gt; ... &amp;gt; arr[arr.length - 1]

//Solution in java

class Solution {
    public boolean validMountainArray(int[] arr) {
        int i = 0;
        int j = arr.length - 1;
        int n = arr.length - 1;
        while (i + 1 &amp;lt; n &amp;amp;&amp;amp; arr[i] &amp;lt; arr[i+1]) {
            i++;
        }

        while (j &amp;gt; 0 &amp;amp;&amp;amp; arr[j] &amp;lt; arr[j-1]) {
            j--;
        }

        return (i &amp;gt; 0 &amp;amp;&amp;amp; i == j &amp;amp;&amp;amp; j &amp;lt; n);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope the solution was easy to understand !If you still have any doubts feel free to reach out to me at Linkedin! I am attaching my linkedin id below, connect or follow to support and asks your doubts there !&lt;br&gt;
Happy Coding! 🐱‍💻&lt;br&gt;
Connect and Follow on &lt;a href="https://www.linkedin.com/in/rubleenkaur2201/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; and &lt;a href="https://github.com/rubleen1903" rel="noopener noreferrer"&gt;Github&lt;/a&gt; to show support !&lt;/p&gt;

</description>
      <category>java</category>
      <category>algorithms</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
