Question: Write code in C++ Given an array of size n such that each element contains either a 'P' for policeman or a 'T' for thief.
Write code in C++
Given an array of size n such that each element contains either a 'P' for policeman or a 'T' for thief. Find the maximum number of thieves that can be caught by the police. Keep in mind the following conditions : 1. Each policeman can catch only one thief. 2. A policeman cannot catch a thief who is more than K units away from him. Example 1:
Input: N = 5, K = 1 arr[] = {P, T, T, P, T}
Output: 2 Explanation: Maximum 2 thieves can be caught. First policeman catches the first thief and the second policeman can catch either the second or third thief. Example 2:
Input: N = 6, K = 2 arr[] = {T, T, P, P, T, P}
Output: 3 Explanation: Maximum 3 thieves can be caught.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
