Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!