Challenge 5: Help the Policemen Catch the thieves!

Given a number of policemen and thieves, calculate the maximum number of thieves that can be caught.

Problem Statement

Implement a function that calculates the number of thieves that can be caught.

Input

An array of size n where each element in the array contains either a policeman (P) or a thief (T).

Each policeman can catch only one thief and a policeman cannot catch a thief who is more than k units away from him.

Output

The maximum number of thieves that can be caught.

Sample Input

    policeThiefArray[] = {'P', 'T', 'T', 'P', 'T'},
    k = 1.

Sample Output

    2

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.