Queen's Attack II Discussions | Algorithms | HackerRank

Sort by

recency

|

1017 Discussions

|

  • + 0 comments

    Good challenge. Also, I found this tool that gives a very detailed analysis of my resume and suggests amazing improvements: www.autointerviewai.com/ats-score . You guys might wanna check it out!

  • + 0 comments

    Given plenty of time, I can complete medium diffcult level problem with lip fillers yaletown. but I cannot complate in half an hour.

  • + 0 comments

    If you’re looking for a great investment or a new home, there are some interesting options available. I recently came across an apartment for sale in Thessaloniki that caught my attention due to its central location and modern amenities. The neighborhood is vibrant, with easy access to shops, cafes, and public transport. Pricing seems reasonable compared to similar properties in the area. I’m curious if anyone has experience buying in Thessaloniki and can share tips on the process or reliable real estate agents. Any advice would be really appreciated!

  • + 0 comments

    I'm failing in a case that maybe I didn't consider. I want to see the discussion to see if someone else had a similar issue or to have ideas of the possible scenarios, instead, I'm getting the Détente Musculaire result. Please avoid pasting here your code. We don't need it, nobody need it!

  • + 0 comments

    Here's my solution in TypeScript:

    (Notice that the arguments for the queen's position are wrong in the original function.)

    type Obstacles = {
      l: number;
      r: number;
      t: number;
      b: number;
      tr: number;
      tl: number;
      br: number;
      bl: number;
    };
    
    function queensAttack(n: number, _k: number, c_q: number, r_q: number, obstacles: number[][]): number {
      const bounds = {
        left: r_q - 1,
        top: n - c_q,
        right: n - r_q,
        bottom: c_q - 1,
      }
      
      const limits = obstacles.reduce<Obstacles>((dict, [coordY, coordX]) => {
        const dX = coordX - r_q;
        const dY = coordY - c_q;
        
        if(dY === 0) {
          if(dX > 0) {
            dict.r = Math.min(dX - 1, dict.r);
          } else {
            dict.l = Math.min(-dX - 1, dict.l);
          }
        } else if (dX === 0) {
          if(dY > 0) {
            dict.t = Math.min(dY - 1, dict.t);
          } else {
            dict.b = Math.min(-dY - 1, dict.b);
          }
        } else if (Math.abs(dX) === Math.abs(dY)) {
          if(dY > 0) {
            if(dX > 0) {
              dict.tr = Math.min(dX - 1, dict.tr);
            } else {
              dict.tl = Math.min(-dX - 1, dict.tl);
            }
          } else {
            if(dX > 0){
              dict.br = Math.min(dX - 1, dict.br);
            } else {
              dict.bl = Math.min(-dX - 1, dict.bl);
            }
          }
        }
        return dict;
      }, {
        t: bounds.top,
        b: bounds.bottom,
        l: bounds.left,
        r: bounds.right,
        tr: Math.min(bounds.top, bounds.right),
        tl: Math.min(bounds.top, bounds.left),
        bl: Math.min(bounds.bottom, bounds.left),
        br: Math.min(bounds.bottom, bounds.right),
      });
      
      return Object.values(limits).reduce((acc, curr) => acc + curr, 0);
    }