<jupyter_start><jupyter_text>**Code Signal Solution for Interview Challenges** **Problem Statement 1:**'''Given an array a that contains only numbers in the range from 1 to a.length, find the first duplicate number for which the second occurrence has the minimal index. In other words, if there are more than 1 duplicated numbers, return the number for which the second occurrence has a smaller index than the second occurrence of the other number does. If there are no such elements, return -1.ExampleFor a = [2, 1, 3, 5, 3, 2], the output should be firstDuplicate(a) = 3.There are 2 duplicates: numbers 2 and 3. The second occurrence of 3 has a smaller index than the second occurrence of 2 does, so the answer is 3.For a = [2, 2], the output should be firstDuplicate(a) = 2;For a = [2, 4, 3, 5, 1], the output should be firstDuplicate(a) = -1.Input/Output[execution time limit] 4 seconds (py3)[input] array.integer aGuaranteed constraints:1 ≤ a.length ≤ 105,1 ≤ a[i] ≤ a.length.[output] integerThe element in a that occurs in the array more than once and has the minimal index for its second occurrence. If there are no such elements, return -1.'''<jupyter_code>def firstDuplicate(a):
    seen = set()
    for i in a:
        if i in seen:
            return i
        seen.add(i)
    return -1

a = [2, 1, 3, 5, 3, 2]
print(firstDuplicate(a))<jupyter_output>{2}
{1, 2}
{1, 2, 3}
{1, 2, 3, 5}
3<jupyter_text>**Problem Statement 2:**Given a string s consisting of small English letters, find and return the first instance of a non-repeating character in it. If there is no such character, return '_'.ExampleFor s = "abacabad", the output should befirstNotRepeatingCharacter(s) = 'c'.There are 2 non-repeating characters in the string: 'c' and 'd'. Return c since it appears in the string first.For s = "abacabaabacaba", the output should befirstNotRepeatingCharacter(s) = '_'.There are no characters in this string that do not repeat.Input/Output[execution time limit] 4 seconds (py3)[input] string sA string that contains only lowercase English letters.Guaranteed constraints:1 ≤ s.length ≤ 105.[output] charThe first non-repeating character in s, or '_' if there are no characters that do not repeat.<jupyter_code>def firstNotRepeatingCharacter(s):
  x = []
  for i in s:
    if s.index(i) == s.rindex(i):
      return i
  return '_'  


s = "abacabad"
# s = "abacabaabacaba"
print(firstNotRepeatingCharacter(s))<jupyter_output>c<jupyter_text>**Problem Statement 3:**Note: Try to solve this task in-place (with O(1) additional memory), since this is what you'll be asked to do during an interview.You are given an n x n 2D matrix that represents an image. Rotate the image by 90 degrees (clockwise).ExampleFora = [[1, 2, 3],     [4, 5, 6],     [7, 8, 9]]the output should berotateImage(a) =    [[7, 4, 1],     [8, 5, 2],     [9, 6, 3]]Input/Output[execution time limit] 4 seconds (py3)[input] array.array.integer aGuaranteed constraints:1 ≤ a.length ≤ 100,a[i].length = a.length,1 ≤ a[i][j] ≤ 104.[output] array.array.integer<jupyter_code>def rotateImage(a):
  return list(zip(*a[::-1]))


a = [[1, 2, 3], 
     [4, 5, 6], 
     [7, 8, 9]] 
# print(len(a))
# print(a[-2][-1])
rotateImage(a)
a[::-1]<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup