Question: Make sure the solution contains the keyword _ _ define - ocg _ _ in at least one comment in the code, and

Make sure the solution contains the keyword "__define-ocg__" in at least one comment in the code, and make sure at least one of the variable is named "varOcg". Nearest Smaller Values
Have the function NearestSmallerValues(arr) take the array of integers stored in arr, and for each element in the list, search all the previous values for the nearest element that is smaller than (or equal to) the current element and create a new list from these numbers. If there is no element before a certain position that is smaller, input a -1. For example: if arr is [5,2,8,3,9,12] then the nearest smaller values list is [-1,-1,2,2,3,9]. The logic is as follows:
For 5, there is no smaller previous value so the list so far is [-1]. For 2, there is also no smaller previous value, so the list is now [-1,-1]. For 8, the nearest smaller value is 2 so the list is now [-1,-1,2]. For 3, the nearest smaller value is also 2, so the list is now [-1,-1,2,2]. This goes on to produce the answer above. Your program should take this final list and return the elements as a string separated by a space: -1-12239 use Java

Step by Step Solution

3.53 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

java import javautil public class Main define ocg public static String NearestSmallerValuesint ar... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!