title: how to display common character if the two letters is equal in vector
body: <p>For example I have vector {'a','a','b','b','c'} and I want to get the most letters which is a and b but this code the output is a;</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  int getMostFrequentElement(std::vector&lt;char&gt; &amp;arr)
  {
      if (arr.empty())
          return -1;
  
      std::sort(arr.begin(), arr.end());
  
      auto last_int = arr.front();
      auto most_freq_int = arr.front();
      int max_freq = 0, current_freq = 0;
  
      for (const auto &amp;i : arr) {
          if (i == last_int)
              ++current_freq;
          else {
              if (current_freq &gt; max_freq) {
                  max_freq = current_freq;
                  most_freq_int = last_int;
              }
  
              last_int = i;
              current_freq = 1;
          }
      }
  
      if (current_freq &gt; max_freq) {
          max_freq = current_freq;
          most_freq_int = last_int;
      }
  
      return most_freq_int;
  }
  
  int main(){
      std::vector&lt;char&gt; arr = {'a','a','b','b','c'};
  
      char ret = getMostFrequentElement(arr);
    
      std::cout &lt;&lt; &quot;Most frequent element = &quot; &lt;&lt; ret;
  
      
  }
  </code></pre>
  <p>May I know why my output becomes a instead a and b?</p>
  <p>input vector arr{'a','a','b','b','c'}
  expected output is a and b</p>
  <p>but my output is a</p>