From 956598cbec1adb389753fcdcb4990678f3b46ba6 Mon Sep 17 00:00:00 2001 From: "Akshat B. Gupta" <129939442+gakshatb@users.noreply.github.com> Date: Tue, 3 Oct 2023 23:49:25 +0530 Subject: [PATCH] Create akshat_array.py --- .../akshat_array.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Find the first non-repeating element in a given array of integers/akshat_array.py diff --git a/Find the first non-repeating element in a given array of integers/akshat_array.py b/Find the first non-repeating element in a given array of integers/akshat_array.py new file mode 100644 index 0000000..6bab387 --- /dev/null +++ b/Find the first non-repeating element in a given array of integers/akshat_array.py @@ -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