Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Solution
- A = [3, 4, 3, 2, 3, -1, 3, 3]
- def solution(A):
- num_list = sorted(list(set(A)))
- ls = []
- for i in range(len(num_list)):
- ls.append(A.count(num_list[i]))
- freq = num_list[ls.index(max(ls))]
- result = []
- for idx in range(len(A)):
- if A[idx] == freq:
- result.append(idx)
- return np.random.choice(result)
- solution(A)
- # Generate test data
- size = np.random.randint(11)
- max_num_size = size // 2 + 1
- A = list(np.random.randint(-2000000000, 2000000000, size=size-max_num_size))
- A_max = np.random.randint(-2000000000, 2000000000, size=1)[0]
- for i in range(max_num_size):
- A.append(A_max)
- # A = A.append(np.random.choice(A), replace=False)
- A
- # Test
Add Comment
Please, Sign In to add comment