Problem:- Consider an array of integers, , where every element in occurs exactly twice except for one unique element.Find and print the unique element.
Input :- 4 9 95 93 57 4 57 93 9 #Input array with 95 as unique element.
Output:- 95
Background of XOR operator ( ^ ) :- Bit-wise operator which results zero, if XOR operator is applied between same bits otherwise gives 1.
We can use XOR operation to reset all bit for two numbers , if they are same. i.e : 3 ^ 3 = 0
Sample output:-
>>>
Enter size of array (Input)
9
Enter elements separated by space
4 9 95 93 57 4 57 93 9
Unique element is
95
Input :- 4 9 95 93 57 4 57 93 9 #Input array with 95 as unique element.
Output:- 95
Background of XOR operator ( ^ ) :- Bit-wise operator which results zero, if XOR operator is applied between same bits otherwise gives 1.
| XOR Operator operation |
Sample program to print unique element using XOR :-
#!/bin/python def lonely_integer(a): storage = a[0] for i in range(1, a.__len__()): storage = storage ^ a[i] #print (storage) return storage print "Enter size of array (Input) " n = int(raw_input().strip()) print "Enter elements separated by space " a = map(int,raw_input().strip().split(' ')) print "Unique element is " print lonely_integer(a)
Sample output:-
>>>
Enter size of array (Input)
9
Enter elements separated by space
4 9 95 93 57 4 57 93 9
Unique element is
95
Aivivu đại lý vé máy bay, tham khảo
ReplyDeleteve may bay di my gia re
đặt vé máy bay đà lạt hà nội
vé máy bay hà nội đến sài gòn
vé máy bay đi nha trang pacific airlines
vé từ mỹ về việt nam
thuê xe đi sân bay nội bài giá rẻ
Combo Quy Nhơn
This is a good example of how the XOR operator can solve an array problem efficiently. Since XOR of two identical numbers is zero and XOR with zero preserves the original number, all duplicate elements cancel each other out, leaving only the unique element. This approach takes O(n) time and uses O(1) extra space, making it an efficient solution for finding a non-repeating element.
DeleteFor beginners who want to strengthen their Python programming skills, Python Online Training in India can help build a solid foundation in operators, loops, arrays, and problem-solving techniques through practical programming exercises.
Practicing problems like this is an effective way to improve logical thinking and prepare for coding interviews. A Python Online Course in India can help learners explore Python fundamentals, bitwise operators, and algorithmic problem-solving at their own pace.
DeleteDDE7B87DD5
ReplyDeletehacker bul
hacker kiralama
tütün dünyası
hacker bulma
hacker kirala
Get complete details about the ATMA 2025 exam on KollegeApply — covering registration steps, pattern, syllabus, and scoring to help you plan your MBA entrance preparation with clarity.
ReplyDelete08449740
ReplyDeleteManisa Esçort
Nevşehir Esçort
Bartın Esçort
Şırnak Esçort
Gümüşhane Esçort
Zonguldak Esçort
Rize Esçort
Düzce Esçort
Van Esçort
3006A031
ReplyDeleteForum
Forum
Forum
Forum
Forum
Forum
Forum
Forum
Forum