TOPIC

Javascript 35% WA

arkanoid asked 3 years ago

Galera, fiz todos os testes do uDebug estão corretos. Alguém sabe o que pode estar faltando?

var input = require("fs").readFileSync("./stdin", "utf8");
var lines = input.split("\n");

let arrayCountDiamond = [];

lines.forEach((element, key, arr) => {
  let auxArray = element.split("");

  if (auxArray.length > 1000) {
    return false;
  }

  if (auxArray.length === 0 && key === arr.length - 1) {
    return false;
  }

  if (/^(?=.*[0-9])/.test(element)) {
    return false;
  }

  let countDiamond = 0;
  let leftDiamondPoint = null;

  function makeDiamond(arr) {
    arr.forEach((element, key) => {
      if (element === "<") {
        leftDiamondPoint = key;
      }
      if (
        leftDiamondPoint !== null &&
        element === ">" &&
        key > leftDiamondPoint
      ) {
        countDiamond++;
        arr.splice(key, 1);
        arr.splice(leftDiamondPoint, 1);
        leftDiamondPoint = null;
        makeDiamond(arr);
      }
    });
  }

  makeDiamond(auxArray);

  arrayCountDiamond.push(countDiamond);
});

for (let index = 0; index < arrayCountDiamond.length; index++) {
  if (arrayCountDiamond.length - 1 === index) {
    console.log(arrayCountDiamond[index]+"\n");
  } else {
    console.log(arrayCountDiamond[index]);
  }
}

Remember not post solutions. Your post may be reviewed by our moderators.

  • NietzscheMartins replied 3 years ago

    acredito que vc usar let leftDiamondPoint = null pode confundir na leftDiamondPoint !== null, tipo quando o key== 0. eu troquei para underfined