import java.util.*;
public class Main
{
public static boolean checkMonotic(ArrayList<Integer> nums, int store) {
int i = 0;
int j = nums.size()-1;
while(i <= j) {
// case 1: increasing order Monotonic
if(nums.get(i) >= nums.get(j)) {
return true;
}
// case 2: decreasing order Monotonic
if(nums.get(i) <= nums.get(j)) {
return true;
}
}
return false;
}
public static void main(String[] args) {
ArrayList<Integer> nums = new ArrayList<>();
// 1, 2, 2, 3 - Monotonic
nums.add(1);
nums.add(2);
nums.add(2);
nums.add(3);
int target = 16;
System.out.println(checkMonotic(nums, target));
}
}
CODE:
No comments:
Post a Comment