The Fellowship of the Ring has started its journey towards Mount Doom to destroy the One Ring. In an unexpected turn of events, Gollum has promised Frodo and Sam to be their guide. Considering how precious the Ring is to Gollum, Sam is suspicious of Gollum’s intentions. However, he is afraid of confronting Gollum without concrete evidence, as it might turn him against them in case deception is not Gollum’s intention. Sam needs the help of someone unbiased to dispel or confirm his suspicions. Sam has marked checkpoints visited by them with a unique character and avoids marking it again if it’s already visited. To help him out you need to write a function that accepts: • checkpoints: a list of checkpoints, each of which is represented by a lowercase letter. A repeated character in this list indicates that a checkpoint has been visited at least twice. The function must calculate the maximum number of times any checkpoint is repeated in the checkpoints. Based on the count, Sam can decide whether repetitions of checkpoints is deliberate or accidental.

Respuesta :

Answer:

Complete code is given below:

Explanation:

First counts dictionary is intitalized empty. Then, traversing the checkpoints list, count of each character is stored in counts dictionary.

Then, value of dictionary are iterated and maximum count is stored in res variable and returned.

Code:

def max_checkpoint(checkpoints):

counts = {}

 

for i in checkpoints:

if i not in counts:

counts[i] = 1

else:

counts[i] = counts[i]+1

 

res = 0

 

for v in counts.values():

if(v>res):

res = v

 

return res

print(max_checkpoint(['c', 'g', 'e', 'a', 'd', 'b', 'a', 'f', 'g', 'd']))

print(max_checkpoint(['n', 's', 's', 't', 's', 'n', 's', 'o']))

print(max_checkpoint(['a', 'b', 'c', 'd', 'c', 'd', 'e', 'b', 'd', 'a', 'e', 'f']))

print(max_checkpoint(['p', 'o', 'y', 'p']))

print(max_checkpoint(['z', 'z', 'z', 'z']))