Home > Software engineering >  Google Kickstart 2022 Problem Record Breaker Wrong Answer
Google Kickstart 2022 Problem Record Breaker Wrong Answer

Time:08-28

Sorry for the formatting. New at posting questions

I was practicing this problem asked in the last round of Google Kick Start 2020. The problem is called Record Breaker and is as follows:

"""

Isyana is given the number of visitors at her local theme park on N consecutive days. The number of visitors on the i-th day is Vi. A day is record breaking if it satisfies both of the following conditions: The number of visitors on the day is strictly larger than the number of visitors on each of the previous days. Either it is the last day, or the number of visitors on the day is strictly larger than the number of visitors on the following day. Note that the very first day could be a record breaking day!

Please help Isyana find out the number of record breaking days.

Input The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with a line containing the integer N. The second line contains N integers. The i-th integer is Vi.

Output For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the number of record breaking days.

Limits Time limit: 20 seconds per test set. Memory limit: 1GB. 1 ≤ T ≤ 100. 0 ≤ Vi ≤ 2 × 105.

Test set 1 1 ≤ N ≤ 1000.

Test set 2 1 ≤ N ≤ 2 × 105 for at most 10 test cases. For the remaining cases, 1 ≤ N ≤ 1000.

Sample

Input 4 8 1 2 0 7 2 0 2 0 6 4 8 15 16 23 42 9 3 1 4 1 5 9 2 6 5 6 9 9 9 9 9 9

Output Case #1: 2 Case #2: 1 Case #3: 3 Case #4: 0

In Sample Case #1, the bold and underlined numbers in the following represent the record breaking days: 1 2 0 7 2 0 2 0.

In Sample Case #2, only the last day is a record breaking day.

In Sample Case #3, the first, the third, and the sixth days are record breaking days.

In Sample Case #4, there is no record breaking day. """

This is the solution I created. It gives a Wrong Answer in the first Test Case but I can't think of any specific case that I have missed.

def sol(testcase):
    days = int(input())
    record_breaking = 0
    greatest = 0
    visitors = [0]   list(map(int, input().split()))   [0]
    for x in range(days 1):
        if x == 0:
            continue
        if visitors[x] > greatest:
            greatest = visitors[x]
            if (visitors[x] > visitors[x-1]) and (visitors[x] > visitors[x 1]):
                record_breaking  = 1
    print(f"Case #{testcase}: {record_breaking}")
    
    
testcases = int(input())
for x in range(testcases):
    sol(x 1)

CodePudding user response:

// Here Is Your Answer Cleared All Test Cases
T = int(input())
for i in range(T):
    N = int(input())
    Vs = [int(v) for v in input().split(" ")]
    max_number = -1
    record_breaks = 0
    for j in range(N):
        first_condition = Vs[j] > max_number
        if j 1 < N:
            second_condition = Vs[j] > Vs[j 1]
        else:
            second_condition = True
        if first_condition and second_condition:
            record_breaks  =1
        if first_condition:
            max_number = Vs[j]
    print("Case #{}: {}".format(str(i 1), str(record_breaks)))
  • Related