





Please login
Prime

Prepinsta Prime
Video courses for company/skill based Preparation
(Check all courses)
Get Prime Video
Prime

Prepinsta Prime
Purchase mock tests for company/skill building
(Check all mocks)
Get Prime mock
Find non-repeating elements in an array

Non-repeating elements
We will see how to find non-repeating elements from an array now. An element is said to be non-repeated element if its frequency is one. we will find this using set concepts. Read the algorithm to understand code.
Given an array print elements whose frequency is one.
Example:
- Input: arr [ ] =[1,2,5,2,6,7,5]
- Output: 1 6 7
Here 1 6 7 are the only elements with frequency one.
Working:
- Step 1: Read the array size
- Step 2: Initialize empty array
- Step 3: Read array elements and store in an array
- Step 4: Iterate through set of array (which eliminates duplicates )
- Step 5: if the element in the set of array has count 1 in array then print that element
Python code:
size=int(input(“ENTER ARRAY SIZE”))
arr=[ ]
for i in range(size):
element=int(input())
arr.append(element)
for i in set(arr):
if arr.count(i)==1:
print(i,end=” “)
ENTER ARRAY SIZE 7
1
2
5
2
6
7
5
1 6 7
Login/Signup to comment