Non-Repeating Element Python

PROGRAM TO FIND THE FIRST NON-REPEATING ELEMENT EFFICIENTLY 



def firstNonRepeating(arr, n):
      
    # Insert all array elements in hash
    # table
    mp={}
    for i in range(n):
        if arr[i] not in mp:
            mp[arr[i]]=0
        mp[arr[i]]+=1
          
    # Traverse through map only and
    for x in mp:
        if (mp[x]== 1):
            print(x,end=" ")
              
# Driver code
arr = [ 9, 4, 9, 6, 7, 4 ]
n = len(arr)
firstNonRepeating(arr, n)


OUTPUT
7 6

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java