The Three Knights

The Three Knights

INTERN

Given a grid with n rows and m columns, count the number of possible placements for three knights on the grid such that no two knights' placements counter each other. Note that no two knights can be placed in the same cell.

It is known that a knight in chess can counter another piece in cell (a2, b2) from the cell (a1, y1) if either (|a1 - a2| = 1 and |b1 - b2| = 2), or (|a1 - a2| = 2 and |b1 - b2| = 1).



Find the number of possible placements for the three knights on the grid such that no two knights can counter each other.


Example 1 :

Input: n = 2, m = 3
Output: 20
Explanation: There are 20 possible placements for the three knights.




Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.