Home › Coding › Below is an instruction that describes a task. Write a respo...
Below is an instruction that describes a task. Write a respo...
Coding · Gemini, GPT-5.6, Claude · Coding
55Quality
88%Useful
85Reliability
The prompt
Below is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: Design an algorithm in Python to find the most common elements in an array of integers. ### Input: [3, 4, 1, 2, 5, 3, 3] ### Output: def most_common(nums): # Create a dictionary to store the counts counts = {} # Iterate over the elements for num in nums: # If the element is not present in the dictionary, add it if num not in counts: counts[num] = 0 # Update the count counts[num] += 1 # Get the maximum count max_count = max(counts.values()) # Return the elements that have maximum count return [num for num, count in counts.items() if count == max_count]