Question on Prompt for Practice Questions Set#2 - Question #1

Not sure if this is the right place to post this (please direct me if it isn’t), what is ‘j2’ of the Practice Problems Set#2, Question 1 suppose to be? Another index? See context below:

Write a function, nearest_larger(arr, i) which takes an array and an

index. The function should return another index, j: this should

satisfy:

(a) arr[i] < arr[j], AND

(b) there is no j2 closer to i than j where arr[i] < arr[j2].

Thanks for any light that can be shed on this!

Hi Andy,

Currently this forum is only serving those preparing for the Full Time Curriculum so everything is in Ruby. That being said let me see if I can help you out.

The question is asking for an integer in return “another index” in which that index points to the number in the array that is the closest larger number to the number at the given index. In some pseudo code one might think the following as a solution:

  1. iterate through the given array
  2. for each number iterate through all numbers in front of this number
  3. for each element check if it is greater
  4. if it is greater then return that index

Try to think of some edge cases as well! Hopefully this helps :smiley:

You can get help with Bootcamp Prep Questions Here

Oops, sorry about that!

But thanks for the help Kevin! After some more wrangling, I got the gist of it.