Algorithm Problems Solutions KMP string matching algorithm N queens problem K queens problem for M*N chessboard