-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Find the first non-repeating element in a given array of integers/akshat_array.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |