CodeChef Logo CodeChef Logo
Courses

Programming and DSA

Learn to think like a programmer. Develop your problem-solving skills with essential data structures and algorithms.

Career Paths

From beginner to job-ready. Explore our curated career paths designed to help you succeed in the tech industry.

Other Courses

Programming and DSA

Explore courses

Catalogue

Programming and DSA

Learn to think like a programmer. Develop your problem-solving skills with essential data structures and algorithms.

Career Paths

From beginner to job-ready. Explore our curated career paths designed to help you succeed in the tech industry.

Other Courses

Explore courses
Practice Compete Compiler
Upgrade to Pro
Courses

Programming and DSA

Learn to think like a programmer. Develop your problem-solving skills with essential data structures and algorithms.

Career Paths

From beginner to job-ready. Explore our curated career paths designed to help you succeed in the tech industry.

Other Courses

Programming and DSA

Explore courses

Catalogue

Programming and DSA

Learn to think like a programmer. Develop your problem-solving skills with essential data structures and algorithms.

Career Paths

From beginner to job-ready. Explore our curated career paths designed to help you succeed in the tech industry.

Other Courses

Explore courses
Practice Compete Compiler
Home » Wiki » Tutorial for The White Knight

Tutorial for The White Knight

 

The White Knight problem asked in codechef contest(July 09) is really one of the simplest problems given in codechef contest. We are asked to find out the maximum number of black pawn that could be captured by white knight by moving in only right direction.

First thing we should observe is that knight can move in four positions. This could be visualized as tree with 4 branches (except at boundary condition). Knight could reach a position from multiple paths. This leads to overlapping sub problems so it should be solved using Dynamic programming.

We would move in a bottom-up(from right to left column) fashion and calculate for each position on the board, the maximum number of pawn that could be captured if White knight moves through that position. Since the total number of cell in board is n2 and calculation for each cell is done only once. So the overall complexity of algorithm is O(n2).

Algorithm:-

  1. Assign the board such that for a pawn at position (i,j) be have 1 and at empty position be have 0.
  2. Iterate right to left toward the white knight.
  3. For each position we would be calculate MAXIMUM of the 4 value that the knight can move from that position.
  4. Add this maximum value to the value at this position and assign newly calculated value for this position.
  5. Continue this process prior to the column of the white knight.
  6. Find the final result similarly.
Workden, MNR PRIDE, 14, HAL Old Airport Rd, Domlur I Stage, 1st Stage, DOMLUR, Bengaluru, Karnataka 560071 [email protected] +91 95911 47880
Find us online

ROADMAPS

Learn Python
Learn Java
Learn C
Learn C++
Data structures and Algorithms
Competitive Programming
More Roadmaps

CAREER PATHS

React JS Developer
Full stack Developer
SQL for Data Analysis
Frontend Developer
Java Backend Developer
Data Analysis using Python
Python Backend Developer
C++ Developer
Machine Learning using Python

COMPILERS

HTML online compiler
C++ online compiler
C online compiler
Java online compiler
Python online compiler
SQL online compiler
JavaScript online compiler
React online compiler
More compilers

COMPANY

About us
For colleges
Coding Contests
Blogs
Contact us
Privacy Policy
Frequently Asked Questions

© 2025 CodeChef Inc. All rights reserved.

We use cookies to improve your experience and for analytical purposes. Read our Privacy Policy and Terms to know more. You consent to our cookies if you continue to use our website.