Skip to content

Commit

Permalink
Create akshat_array.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gakshatb authored Oct 3, 2023
1 parent bbda3f6 commit 956598c
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from collections import Counter

def first_non_repeating_element(arr):
# Count the occurrences of each element in the array
element_count = Counter(arr)

# Iterate through the array and find the first non-repeating element
for element in arr:
if element_count[element] == 1:
return element

return None # Return None if no non-repeating element is found

# Example usage
arr = [9, 3, 2, 6, 6, 1, 9, 2, 4, 3]
first_non_repeating = first_non_repeating_element(arr)
print("First non-repeating element:", first_non_repeating) # Output: 1

0 comments on commit 956598c

Please sign in to comment.