DOLL - Editorial

PROBLEM LINK: Red Light, Green Light

Setter: Reyaan Jagnani
Editorialist: Arpan Gupta

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Arrays

PROBLEM:

Gi-Hun and Ali both have a height K and there are N people standing between these two with height A_i. A line of sight is a straight line drawn between the topmost point of two objects. Find the minimum number of players that need to be removed such that there is no other player blocking the line of sight between Gi-Hun and Ali. Players having the same height as of Gi-Hun and Ali don’t block the line of sight.

EXPLANATION:

Since both Gi-Hun and Ali have the same height, therefore all players having a height greater than K will block the line of sight and needs to be removed.

So for an i_{th} person, if the height is greater than K, we will eliminate this person.

Time Complexity: O(n)
Space Complexity: O(n)

SOLUTIONS:

Setter's Solution(C++)
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int arr[n];
        int ans = 0;
        for(int i=0; i<n; i++)
        {
            cin>>arr[i];
        }
        for(int i=0; i<n; i++)
        {
            if(arr[i]>k) ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
Setter's Solution(Python)
T=int(input())
for _ in range(T):
    N,K=list(map(int,input().split()))
    A=list(map(int,input().split()))
    ans=0
    for i in range(N):
        if (A[i]>K):
            ans=ans+1

    print(ans)

For doubts, please leave them in the comment section, I’ll address them.