Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Capture the Pawns
EASY
15 mins
2 upvotes
Strings
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Strings
-
-
Other topics
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Capture the Pawns

Contributed by
srejanbera
Easy
yellow-spark
0/40
Avg time to solve 15 mins
Success Rate 75 %
Share
2 upvotes

Problem Statement

Ninja is learning how to play chess. He is still a beginner, so his friend gave him a simple puzzle. The given situation of the chessboard has only one white Rook ‘R’, some white bishops ‘B’ and some black pawns ‘P’. The task is to find the number of pawns that can be captured by the Rook. Can you help Ninja to solve this problem?

You are given a list of 8 strings of size 8 characters each to describe the position of the pieces. Find the number of pawns that can be captured by the Rook

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
******** ******** ***R***P ******** ***P****  ******** ***P**** ********  
Sample Output 1:
2
Explanation of sample input 1:

altImage

The white rook will attack the pawns at d5 and h6. Hence, the answer is 2.
Sample Input 2:
***P**** ***B**** P**R***P ******** ***P****  ******** ***P**** ********    
Sample Output 2:
3
Reset Code
Full screen
Auto
copy-code
Console