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

113
Views
Find Peak Element in a Bitonic Array

I'm trying to solve a challenge - given an bitonic array, find the element index of its peak or trough. If the array is not bitonic, return a value of -1. I've set up my if-else statements as follows:


for (let i = 1; i < arr.length; i++) {
  if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {
        let resultOne = arr.indexOf(arr[i]);
        return resultOne;
      }
  else if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]){
       let resultTwo = arr.indexOf(arr[i]); 
        return ResultTwo;
      }

  else {return -1;}
}

}

Every time it runs tests, the result is -1, which means the first two conditions are never met. Why, based on this, are these conditions never met? Thanks

about 4 years ago · Juan Pablo Isaza
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!