title: Programming Question to find lowestMaxVisits in Array
body: <p>Happy Holidays. I was given a question to solve in less than o(n^2). Given a list of integers, where each number represents the marker in a trail and the runner runs from one marker to another marker and after all the sprints, we need to find the lowest max visits of the marker.</p>
  
  <p>For example, given an array like [1,5,2,7,3,10], we have to return the marker 3 as it is the lowest marker where the runner has crossed maximum times.</p>
  
  <pre><code>package io.sort;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  public class LowestMaxVisitsNumberInArray {
      public static void main(String[] args) {
          List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
          list.add(1);
          list.add(5);
          list.add(2);
          list.add(7);
          list.add(3);
          list.add(10);
          int [] arr = new int[10];
          List&lt;Integer&gt; list1 = new ArrayList&lt;&gt;();
          long smillis = System.currentTimeMillis() % 1000;
          for(int i=0; i&lt;list.size()-1; i++){
              int start = list.get(i)-1;
              int end = list.get(i+1)-1;
              if(start &gt; end){
                  int temp = start;
                  start = end;
                  end = temp;
              }
              for(int j=start; j&lt;=end; j++){
                  arr[j]++;
              }
          }
          int maxVisits = -1;
          int index = -1;
          for(int k=0;k&lt;arr.length;k++){
              if(arr[k] &gt; maxVisits){
                  index = k;
                  maxVisits = arr[k];
              }
          }
          System.out.println("Here is the final array"+Arrays.toString(arr));
          long emillis = System.currentTimeMillis() % 1000;
          System.out.println("Time taken---"+ (emillis-smillis));
          System.out.println("Here is the highest---"+(index+1));
      }
  }
  </code></pre>
  
  <p>Here is my program which is o(n^2). Is there a better way to do this.</p>
  
  <p>Thanks in advance.</p>