Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

112
Visualizações
Find position of symmetrical array

Referring to picture below at here, x and y means coordinates. For symmetrical coordinates part, the numbering will be symmetrical also and if its not symmetrical, it will keep adding i+1 index. For coordinates that is equal to each other side by side, the index will stay constant. I have attached a codepen file at here for javascript playground. The output that I want is the index in array as shown in picture. How do I go about in solving this algorithm :)?

Thank you for reading

   x_all=[102,152, 202,252 ,202,152, 302,454 ,8745,8745 ,25, 25, 23, 10 , 332, 10 , 67 , 90, 67 ,8967];
   y_all=[12, 153, 20,  52, 20, 153, 302,8745,9065,9065, 52, 34, 9  ,232, 9  , 232, 89  ,91,  89 ,8954];

arr=[];
jj=0
for (let i=0;i<x_all.length;i++){
  if (x_all[i+1]==x_all[i-1]){
    console.log(i)
     jj=jj-1;
    arr.push(jj+1)
  }
    arr.push(jj)
  jj=jj+1;

}
console.log(arr)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

PARTIAL ANSWER DISCLAIMER: I did not fully comprehend the question (The image in the question - https://ibb.co/qssJk3K - is also not accessible!) - and so this is in no way the complete answer.

but meh 🤷‍♀️ found it somewhat interesting to solve so tried this. Hope it helps.

Here's what I tried - For

x_all=[102,152, 202,252 ,202,152, 302,454 ,8745,8745 ,25, 25, 23, 10 , 332, 10 , 67 , 90, 67 ,8967];

  1. Found enclosing palindromes and added them to a palindrome_x

     [[152,202,252,202,152],
        [8745,8745],
        [25,25],
        [10,332,10],
        [67,90,67]]
    
  2. Used an indexes array to push and pop as required. So the

Final Output For x: 1,2,3,4,3,2,5,6,7,7,8,8,9,10,11,10,12,13,12,14

Not sure if this is what is required... But there are commented console.log-er statements for further debugging.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda