|
| 1 | +# Policemen catch thieves |
| 2 | + |
| 3 | +Given an array of size n that has the following specifications: |
| 4 | + |
| 5 | +Each element in the array contains either a policeman or a thief. |
| 6 | +Each policeman can catch only one thief. |
| 7 | +A policeman cannot catch a thief who is more than K units away from the policeman. |
| 8 | +We need to find the maximum number of thieves that can be caught. |
| 9 | +Examples: |
| 10 | + |
| 11 | +```bash |
| 12 | +Input : arr[] = {'P', 'T', 'T', 'P', 'T'}, |
| 13 | + k = 1. |
| 14 | +Output : 2. |
| 15 | +``` |
| 16 | +Here maximum 2 thieves can be caught, first |
| 17 | +policeman catches first thief and second police- |
| 18 | +man can catch either second or third thief. |
| 19 | + |
| 20 | +``` |
| 21 | +Input : arr[] = {'T', 'T', 'P', 'P', 'T', 'P'}, |
| 22 | + k = 2. |
| 23 | +Output : 3. |
| 24 | +``` |
| 25 | +``` |
| 26 | +Input : arr[] = {'P', 'T', 'P', 'T', 'T', 'P'}, |
| 27 | + k = 3. |
| 28 | +Output : 3. |
| 29 | +``` |
0 commit comments