title: Print the first, second occurred character in a list
body: <p>I working on a simple algorithm which prints the first character who occurred twice or more.</p>
  
  <pre><code>for eg:
  
  string ='abcabc'
  output = a
  
  string = 'abccba'
  output = c
  
  string = 'abba'
  output = b
  </code></pre>
  
  <p>what I have done is:</p>
  
  <pre><code>string = 'abcabc'
  s = []
  
  for x in string:
       if x in s:
            print(x)
            break
       else:
            s.append(x)
  
  
  output: a
  </code></pre>
  
  <p>But its time complexity is O(n^2), how can I do this in O(n)?</p>