Queen's Attack II Discussions | Algorithms | HackerRank
  • + 0 comments

    Hint 1- Just check all obstacles that they are on one of four lines. Then you will have at maximun eight obstacles. Hint 2 - then just calculate distance to obstacle or edge of the board.

    public static boolean isPointOnLines(int xc, int yc, int xt, int yt) {
        if (yt == yc && xt != xc) {
            return true;
        }
        if (xt == xc && yt != yc) {
            return true;
        }
        if ((xt - xc) == (yt - yc)) {
            return true;
        }
        if ((xt - xc) == (yc - yt)) {
            return true;
        }
        return false;
    }