Problem:-
You are given a grid of size that has the following specifications:
- Each cell in the grid contains either a policeman or a thief.
- A policeman can only catch a thief if both of them are in the same row.
- Each policeman can only catch one thief.
- A policeman cannot catch a thief who is more than K units away from the policeman.
Write a program to find the maximum number of thieves that can be caught in the grid.
Input format
- First line: T (number of test cases)
For each test case - First line: Two space-separated integers N and K
- Next N lines: N space-separated characters (denoting each cell in the grid)
Output format
For each test case, print the maximum number of thieves that can be caught in the grid.
Constraints
Total Thieves = 5
Number of thieves reachable by policemen in Row 1 = 1
Number of thieves reachable by policemen in Row 2 = 2
Number of thieves reachable by policemen in Row 3 = 1
However, one policeman can catch at most 1 thief. Hence, in Row 2, only 1 thief is catchable.
Therefore, the 3 thieves can be caught.
Code:-
Solution 1 ( C language):-
Solution 2 ( C++ language):-
Solution 3 (java language):-
keywords:-
the policeman catches thieves,the policeman catches thieves meaning in hindi,a special unit is formed within the police force of n policemen such that no policemen,policemen catch thieves leetcode,who catches thieves and robber,police and thieves gfg,who catches thieves in hindi,print the maximum number of thieves that can be caught in the grid,
Recommended Post:-
- codechef problems:-
Wipro :-
- Update the booking ID | Wipro previous year question paper solution
- Pages in PDF
- Find the location id
- Find the odd digits
- Find the Product ID
Infytq :-
Key Points;-
Hackerrank:-
- Python : missing characters : hackerrank solution
- Python : string transformation | Hackerrank solution
- Active Traders certification test problem | Hackerrank Solution
- Usernames changes certification test problem | Hackerrank Solution
- string Representation of objects certification test hackerrank solution
- Average Function | hackerrank certification problem solution
C-tutorial:-
- Micros in C
- Pointer in c
- Function declaration
- Types of user define function
- return type of function
- 2D array
- c program to convert specified days into years weeks and days
- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation
0 Comments