package leetcode;

import java.util.List;

/**
 * https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/
 */
public class Problem1333 {
    public List<Integer> filterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1333 prob = new Problem1333();
        System.out.println(prob.filterRestaurants(
            new int[][]{{1,4,1,40,10},{2,8,0,50,5},{3,8,1,30,4},{4,10,0,10,3},{5,1,1,15,1}},
        1, 50, 10)); // [3,1,5]
        System.out.println(prob.filterRestaurants(
            new int[][]{{1,4,1,40,10},{2,8,0,50,5},{3,8,1,30,4},{4,10,0,10,3},{5,1,1,15,1}},
            0, 50, 10)); // [4,3,2,1,5]
        System.out.println(prob.filterRestaurants(
            new int[][]{{1,4,1,40,10},{2,8,0,50,5},{3,8,1,30,4},{4,10,0,10,3},{5,1,1,15,1}},
            0, 30, 3)); // [4,5]
    }
}

package leetcode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/
 */
public class Problem1333 {
    public List<Integer> filterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {
        List<int[]> list = new ArrayList<>();
        for (int[] restaurant : restaurants) {
            if (restaurant[3] <= maxPrice && restaurant[4] <= maxDistance) {
                if ((veganFriendly == 1 && restaurant[2] == veganFriendly) || veganFriendly == 0) {
                    list.add(restaurant);
                }
            }
        }
        Collections.sort(list, (a, b) -> {
            int cmp = b[1] - a[1];
            if (cmp == 0) {
                return b[0] - a[0];
            }
            return cmp;
        });
        return list.stream().map(a -> a[0]).collect(Collectors.toList());
    }
}

Solve problem 1333