title: finding count of minima or maxima in a set of numbers
body: <blockquote>
    <p>The user inputs n number of datas to be followed in the next line and
    then it inputs n numbers a1,a2,...,an. These numbers are heights of a
    some mountains. The set of these numbers is "ACCEPTABLE" if there is
    only one maxima or minima. for example "1 2 3 2 1", has only one
    maxima which is 3. Also "1 2 3 4" has one maxima. but "1 10 9 8 7 6 5
    6 7" is not acceptable because it has two maxima (10 and 7) or two
    minima (1 and 5).</p>
    
    <p>In other word, the set is acceptable if and only if it is in one of
    this forms:</p>
    
    <p>a1&lt;=a2&lt;=a3 ... &lt;= ai > a(i+1) > ... >an</p>
    
    <p>or</p>
    
    <p>a1>=a2>=a3 ... >= ai &lt; a(i+1) &lt; ... &lt; an.</p>
  </blockquote>
  
  <p>I must submit the answer in a judge system which tests it with unknown test cases. <strong>Using any type of Array or Vector is completely prohibited.</strong></p>
  
  <p>My solution is this:</p>
  
  <pre><code>//C code.
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int n,temp;
      scanf("%d",&amp;n);
      if (n==1)
      {
          int l;
          scanf("%d",&amp;l);
          printf("Yes");
      }
      else
  {
      int a,b;
      int last;
      int changes =0;
      int dec =0 , inc =0; //flag: checking if the set is incremental or decremental till now
      scanf("%d %d",&amp;a,&amp;b);
  
      if (a&gt;b)
      {
          dec=1;
      }
      else if (a&lt;b)
      {
          inc = 1;
      }
      else
      {
          inc =1;
          dec = 1;
      }
      last = b;
      for (int i =2;i&lt;n;i++)
      {
  
          scanf("%d",&amp;temp);
          if (temp&gt;last &amp;&amp; dec==1)
          {
              inc = 1;
              dec= 0;
              changes++;
          }
          if (temp&lt;last &amp;&amp; inc==1)
          {
              inc =0;
              dec=1;
              changes++;
          }
  
  
  if (!(inc==1 &amp;&amp; dec==1) &amp;&amp; temp == last)
          {
              changes++;
          }
      last = temp;
          last = temp;
      }
      if (changes &lt;=1)
      {
  
          printf("Yes");
      }
      else
      {
          printf("No");
      }
  }
      return 0;
  }
  </code></pre>
  
  <p>It gets the right answer for the examples that are in the question but it fails on some unknown test cases. Any idea how to fix this? Can anyone give me a test case that is not solved right in this code?</p>
  
  <p>P.1:
  I added</p>
  
  <pre><code>if (!(inc==1 &amp;&amp; dec==1) &amp;&amp; temp == last)
      {
          changes++;
      }
  </code></pre>
  
  <p>and it accepted one of the failing test cases but still one remains.</p>
  
  <p>P.2:</p>
  
  <p>This is my other algorithm which fails on some test cases but the judge accepts its answers on the failing test cases of the first one:</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int n;
      int inc=0;
      int dec=0;
      int peak=0;
      int valley=0;
      int last = -1;
      int a;
      scanf("%d",&amp;n);
      for (int i =0;i&lt;n;i++)
      {
          if (last!=-1)
          {
              last =a;
          }
          scanf("%d",&amp;a);
          if (last!=-1)
          {
              if (a&gt;last)
              {
                  if (!(inc==1))
                  {
                      valley++;
                      inc =1;
                      dec=0;
                  }
              }
              if (a&lt;last)
              {
                  if (!(dec==1))
                  {
                      peak++;
                      dec=1;
                      inc =0;
                  }
              }
          }
          last =0;
  
  
      }
      if (valley&lt;=1 &amp;&amp; peak&lt;=1)
      {
          // printf("valley: %d , peak:%d",valley,peak);
          printf("Yes");
      }
      else
      {
          printf("No");
      }
      return 0;
  }
  </code></pre>
  
  <p>P.3</p>
  
  <p>New algorithm:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      long long int n,temp;
      scanf("%lld",&amp;n);
      if (n==1)
      {
          long long int l;
          scanf("%lld",&amp;l);
          printf("Yes");
      }
      else
  {
      long long int a,b;
      long long int last;
      long long int changes =0;
      int dec =0 , inc =0; //flag: checking if the set is incremental or decremental till now
      scanf("%lld %lld",&amp;a,&amp;b);
  
      if (a&gt;b)
      {
          dec=1;
      }
      else if (a&lt;b)
      {
          inc = 1;
      }
      else
      {
          inc =1;
          dec = 1;
      }
      last = b;
      for (long long int i =2;i&lt;n;i++)
      {
  
          scanf("%lld",&amp;temp);
          if (temp&gt;last &amp;&amp; dec==1)
          {
              inc = 1;
              dec= 0;
              changes++;
          }
          if (temp&lt;last &amp;&amp; inc==1)
          {
              inc =0;
              dec=1;
              changes++;
          }
          if (changes&gt;=1 &amp;&amp; temp == last)//new change
          {
              changes+=100;
          }//end of new change
          last = temp;
      }
      if (changes &lt;=1)
      {
  
          printf("Yes");
      }
      else
      {
          printf("No");
      }
  }
      return 0;
  }
  </code></pre>