Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
0
Indexable
Never
package Dec7;

import java.util.ArrayList;
import java.util.List;

public class Q5 {

    public static final <T> void print(T t) {
        System.out.println(t);
    }

    public static void main(String[] args) {

        List<Integer> hills = new ArrayList<Integer>();
        hills.add(1);
        hills.add(4);
        hills.add(5);
        hills.add(8);
        hills.add(9);
        hills.add(10);
        hills.add(7);
        hills.add(6);
        hills.add(3);
        hills.add(2);

        int n = hills.size();
        List<Integer> res = new ArrayList<Integer>();
        for (int i = 1; i < n; i++) {
            res.add(0);
        }

        for (int i = 1; i < n; i++) {
            int currH = hills.get(i);

            int left = i - 1, right = i + 1;
            boolean isLeftTrue = false, isRightTrue = false;
            while (left >= 0) {
                if (hills.get(left) < hills.get(i)) {
                    isLeftTrue = true;
                    break;
                }
                left--;
            }
            while (right < n) {
                if (hills.get(right) < hills.get(i)) {
                    isRightTrue = true;
                    break;
                }
                right++;
            }

            if (isLeftTrue && isRightTrue) {
                res.set(i, 1);
            }
        }
    }
}
Leave a Comment