Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions am_i_N_repeated_in_2N_?_solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Define a function named 'check' that takes a list 'b', [b is our string] as input
def check(b):
# Create an empty dictionary 'temp' to store counts of each element in 'b'
temp = {}

# Loop through each element 'i' in the list 'b'
for i in b:
# Check if 'i' is already in the 'temp' dictionary
if i in temp:
# If it is, increment its count by 1
temp[i] += 1
else:
# If it's not, add it to the dictionary with a count of 1
temp[i] = 1

# Initialize variables 'count' and 'rep_num' to keep track of the most common element and its count
rep_num = 0
count = 0

# Loop through the items in the 'temp' dictionary
for n, c in temp.items():
# Check if the count 'c' is greater than the current maximum count 'count'
if c > count:
# If it is, update 'count' and 'rep_num' with the new maximum values
count = c
rep_num = n

# Return the most common element 'rep_num' as the result
return rep_num

# Input: Read an integer 'a'
a = int(input())

# Input: Read a list of integers 'b'
b = list(map(int, input().split()))

# Call the 'check' function with the list 'b' and print the result
print(check(b))