Challenge: Help the Police Officers Catch the Thieves
Given a number of police officers and thieves, calculate the maximum number of thieves that can be caught.
We'll cover the following
Problem statement
Implement a function that calculates the number of thieves that can be caught.
Input
The input is an array in which each element contains either a police officer (P
) or a thief (T
).
Each police officer can catch only one thief, and a police officer cannot catch a thief who is more than
k
units away from him.
Output
The output is 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.