Skip to content

Google Kick Round-D Question (2020)

• Difficulty Level : Easy
• Last Updated : 04 Aug, 2021

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:

1. The number of visitors on the day is strictly larger than the number of visitors on each of the previous days.
2. 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.

Hey geek! It's time to become a success story instead of reading them. Check out our most renowned DSA Self Paced Course, now at a student-friendly price and become industry ready. And if you are looking for a more complete interview preparation resource, check out Complete Interview Preparation Course that will prepare you for the SDE role of your dreams!

Feeling prepared enough for your interview? Test your skills with our Test Series that will help you prepare for top companies like Amazon, Microsoft, TCS, Wipro, Google and many more!

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
Output
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```
```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.

C++

 `// C++ program for the above approach``#include ``using` `namespace` `std;` `int` `calculate(vector<``int``>& arr, ``int` `n)``{``    ``int` `cnt = 0;``    ``// initialising prevmax as -infinity``    ``int` `prevmax = INT_MIN;` `    ``for` `(``int` `i = 0; i < n; i++) {``        ``// check for condition 2``        ``if` `(i == n - 1) {``            ``if` `(arr[i] > prevmax)``                ``cnt++;``        ``}``        ``// check for condition 1``        ``else` `if` `(arr[i] > prevmax && arr[i] > arr[i + 1]) {``            ``cnt++;``        ``}``        ``// update prevmax``        ``prevmax = max(prevmax, arr[i]);``    ``}` `    ``return` `cnt;``}` `int` `main()``{` `    ``int` `t = 1;``    ``// Taking the input for every test case``    ``while` `(t--) {``        ``int` `n = 9;``        ``vector<``int``> arr = { 3, 1, 4, 1, 5, 9, 2, 6, 5 };``        ``cout << calculate(arr, n) << endl;``    ``}` `    ``return` `0;``}`

Java

 `// JAva program for the above approach``import` `java.io.*;` `class` `GFG{` `    ``static` `int` `calculate(``int``[] arr, ``int` `n)``    ``{``        ``int` `cnt = ``0``;``        ``// initialising prevmax as -infinity``        ``int` `prevmax = Integer.MIN_VALUE;``    ` `        ``for` `(``int` `i = ``0``; i < n; i++) {``            ``// check for condition 2``            ``if` `(i == n - ``1``) {``                ``if` `(arr[i] > prevmax)``                    ``cnt++;``            ``}``            ``// check for condition 1``            ``else` `if` `(arr[i] > prevmax && arr[i] > arr[i + ``1``]) {``                ``cnt++;``            ``}``            ``// update prevmax``            ``prevmax = Math.max(prevmax, arr[i]);``        ``}``    ` `        ``return` `cnt;``    ``}` `    ``// Driver Code``    ``public` `static` `void` `main (String[] args)``    ``{``    ` `        ``int` `t = ``1``;``        ``// Taking the input for every test case``        ``while` `(t-- != ``0``) {``            ``int` `n = ``9``;``            ``int` `arr[] = { ``3``, ``1``, ``4``, ``1``, ``5``, ``9``, ``2``, ``6``, ``5` `};``            ``System.out.println(calculate(arr, n));``        ``}``    ``}``    ` `}` `// This code is contributed by shubhamsingh10`

Python3

 `# Python program for the above approach``def` `calculate(arr, n):``    ` `    ``cnt ``=` `0``    ` `    ``# initialising prevmax as -infinity``    ``prevmax ``=` `-``2``*``*``31``    ` `    ``for` `i ``in` `range` `(n):``      ` `        ``# check for condition 2``        ``if` `(i ``=``=` `n ``-` `1``):``            ``if` `(arr[i] > prevmax):``                ``cnt``+``=``1``        ` `        ``# check for condition 1``        ``elif``(arr[i] > prevmax ``and` `arr[i] > arr[i ``+` `1``]):``            ``cnt``+``=``1``        ` `        ``# update prevmax``        ``prevmax ``=` `max``(prevmax, arr[i])``    ``return` `cnt``    ` `t ``=` `1``# Taking the input for every test case``while` `(t) :``    ``n ``=` `9``    ``arr ``=`  `[``3``, ``1``, ``4``, ``1``, ``5``, ``9``, ``2``, ``6``, ``5``]``    ``print``(calculate(arr, n))``    ``t``-``=``1` `    ``# This code is contributed by shivanisinghss2110.`

C#

 `// C# program for the above approach``using` `System;` `public` `class` `GFG{``    ` `    ``static` `int` `calculate(``int``[] arr, ``int` `n)``    ``{``        ``int` `cnt = 0;``      ` `        ``// initialising prevmax as -infinity``        ``int` `prevmax = Int32.MinValue;``    ` `        ``for` `(``int` `i = 0; i < n; i++)``        ``{``          ` `            ``// check for condition 2``            ``if` `(i == n - 1) {``                ``if` `(arr[i] > prevmax)``                    ``cnt++;``            ``}``          ` `            ``// check for condition 1``            ``else` `if` `(arr[i] > prevmax && arr[i] > arr[i + 1]) {``                ``cnt++;``            ``}``            ``// update prevmax``            ``prevmax = Math.Max(prevmax, arr[i]);``        ``}``    ` `        ``return` `cnt;``    ``}` `    ``// Driver Code``    ``static` `public` `void` `Main ()``    ``{``        ``int` `t = 1;``      ` `        ``// Taking the input for every test case``        ``while` `(t-- != 0)``        ``{``            ``int` `n = 9;``            ``int``[] arr = { 3, 1, 4, 1, 5, 9, 2, 6, 5 };``            ``Console.Write(calculate(arr, n));``        ``}``    ``}``}` `// This code is contributed by shubhamsingh10`

Javascript

 ``
Output
`3`

My Personal Notes arrow_drop_up