title: Find the largest span between the same number in an array
body: <p><br>
                   Merry Christmas and hope you are in great Spirits,I have a Question in Java-Arrays as shown below.Im stuck up with this struggling to get it rite.</p>
  
  <p><code>Consider the leftmost and righmost appearances of some value in an array. We'll say that the "span" is the number of elements between the two inclusive. A single value has a span of 1. Write a **Java Function** that returns the largest span found in the given array.</code></p>
  
  <p>**Example:<br>
  maxSpan({1, 2, 1, 1, 3}) → 4,answer is 4 coz MaxSpan between 1 to 1 is 4<br>
  maxSpan({1, 4, 2, 1, 4, 1, 4}) → 6,answer is 6 coz MaxSpan between 4 to 4 is 6<br>
  maxSpan({1, 4, 2, 1, 4, 4, 4}) → 6,answer is 6 coz Maxspan between 4 to 4 is 6 which is greater than MaxSpan between 1 and 1 which is 4,Hence 6>4 answer is 6.    </p>
  
  <p>I have the code which is not working,it includes all the Spans for a given element,im unable to find the MaxSpan for a given element.</p>
  
  <p>Please help me out.</p>
  
  <p><strong>Results of the above Program are as shown below</strong></p>
  
  <p><strong>Expected This Run<br>
  maxSpan({1, 2, 1, 1, 3}) → 4 5 X<br>
  maxSpan({1, 4, 2, 1, 4, 1, 4}) → 6 8 X<br>
  maxSpan({1, 4, 2, 1, 4, 4, 4}) → 6 9 X<br>
  maxSpan({3, 3, 3}) → 3 5 X<br>
  maxSpan({3, 9, 3}) → 3 3 OK<br>
  maxSpan({3, 9, 9}) → 2 3 X<br>
  maxSpan({3, 9}) → 1 1 OK<br>
  maxSpan({3, 3}) → 2 3 X<br>
  maxSpan({}) → 0 1 X<br>
  maxSpan({1}) → 1 1 OK</strong> </p>
  
  <p>::Code::    </p>
  
  <pre><code>public int maxSpan(int[] nums) {    
      int count=1;//keep an intial count of maxspan=1    
      int maxspan=0;//initialize maxspan=0    
      for(int i=0;i&lt;nums.length;i++){    
          for(int j=i+1;j&lt;nums.length;j++){    
                if(nums[i] == nums[j]){
                   //check to see if "i" index contents == "j" index contents    
                   count++;    //increment count
                   maxspan=count;  //make maxspan as your final count  
                   int number = nums[i]; //number=actual number for maxspan               
                }                            
          }       
      }    
    return maxspan+1; //return maxspan        
  }    
  </code></pre>