visa codesignal 17/11/2025 - failed
440

I failed just a moment ago. Hope this helps you. The first two questions are exactly like these:

# Input -> Output 
# text = "" -> 0 
# text = "abc" -> 1 
# text = "abcxccc" -> 2

# Rule: If the first and last character of a triple substring is same count += 1

def count_triples(text):
    count = 0
    for i in range(len(text) - 2):
        if text[i] == text[i+2]:
            count += 1
    return count


# add each digits of the numbers 
# if the result is not a digit repeat the process. 
# return the max sum readings = [123, 456, 789, 101] 
# first round -> 1+2+3 4+5+6 7+8+9 1+0+1 -> 6, 15, 24, 2 
# second round -> 6 1+5 2+4 2 -> 6, 6, 6, 2 
# max = 6 -> output = 6

def digit_root(n):
    while n > 9:
        s = 0
        for ch in str(n):
            s += int(ch)
        n = s
    return n

def max_digit_root(readings):
    roots = [digit_root(num) for num in readings]
    return max(roots)
Comments (3)