Elements Appearing More Than Once
Find elements that appear more than once.
IntermediatePhase 4 - Level 4: Aggregation & ComparisonExample 10 of 10
elements-appearing-more-than-once.py
1# Take array2n = int(input("Enter array size: "))3arr = []4for i in range(n):5 arr.append(int(input(f"Element {i+1}: ")))67# Find duplicates8freq = {}9for element in arr:10 freq[element] = freq.get(element, 0) + 11112# Find elements appearing more than once13duplicates = []14for element, count in freq.items():15 if count > 1:16 duplicates.append(element)1718print(f"Elements appearing more than once: {duplicates}")
Output
Enter array size: 6 Element 1: 1 Element 2: 2 Element 3: 2 Element 4: 3 Element 5: 3 Element 6: 3 Elements appearing more than once: [2, 3]
What's going on
Count frequency and filter duplicates.
Key Concepts:
Count frequency of each element
Check if count > 1
Collect duplicates
🔗Related Content
- 📖
Phase 4 - Learn Concepts
Review Phase 4 concepts and explanations
- 📝
Phase 4 - Quiz
Test your Phase 4 understanding with quiz questions
- 💻
Phase 4 - All Practice Problems
Explore all practice problems for Phase 4
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum