MBTI
InterviewTime limit1sMemory limit1024 MB
Count how many times each of the 16 four-letter MBTI type codes appears in any of the eight directions on an N by M letter grid.
- Level
Easy3 of 10
- Topics
- Matrix, String matching, Brute force
- Solved
- No attempts yet
Problem
The Myers-Briggs Type Indicator (MBTI) is a self-report questionnaire that describes psychological preferences in how people perceive the world and make decisions.
MBTI divides personality into 16 types. Each type is written with 4 letters.
- The first letter is extroversion (E) or introversion (I), which shows how a person gains energy.
- The second letter is intuition (N) or sensation (S), which shows how a person understands and interprets new information.
- The third letter is feeling (F) or thinking (T), which shows how a person makes decisions.
- The last letter is perception (P) or judgment (J), which shows how a person organizes their time and lifestyle.
All 16 types are formed by choosing one letter from each pair, for example ENFP, ISTP, or ENTJ.
You find an alphabet board on the way to the lab. You are obsessed with MBTI, so you want to count how many MBTI types appear on the board.
If four letters in a horizontal, vertical, or diagonal line form one of the MBTI types, shout "MBTI!". The direction of reading does not matter. The word can be read from bottom right to top left, from left to right, and so on. A type that was already found still earns a shout if it appears at a different location or in a different direction.
Find every MBTI type on the board and shout "MBTI!" for each one.
Input
The first line contains two integers and (), the number of rows and columns of the board.
The next lines each contain uppercase letters, which form the alphabet board.
Output
Print one line with the total number of times "MBTI!" is shouted. This equals the total number of occurrences of the 16 MBTI types on the board.
Hint
In Figure 1, ENFP is found along the diagonal from (0,3) to (3,0).
In Figure 2, INFP is found along the diagonal from (3,3) to (0,0), and ISTJ is found along the horizontal line from (3,3) to (3,0).
In Figure 3, ISFJ is found along the diagonal from (0,0) to (3,3). A second ISFJ is found along the horizontal line from (1,0) to (1,3), and ESTJ is found along the vertical line from (0,1) to (3,1).


