14. Police and Thieves
β GFG solution for the Police and Thieves problem using an optimized two pointers greedy approach to maximize caught thieves. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = ['P', 'T', 'T', 'P', 'T'], k = 1
Output: 2
Explanation: Maximum 2 thieves can be caught. First policeman catches first thief and second
policeman can catch either second or third thief.Example 2
Input: arr[] = ['T', 'T', 'P', 'P', 'T', 'P'], k = 2
Output: 3
Explanation: Maximum 3 thieves can be caught.π Constraints
β
My Approach
Two Pointers Strategy
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
π§βπ» Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated