Jim and the Orders

  • + 0 comments

    unorthodox java solution but i assume very less space complexity

    class Result {

    /*
     * Complete the 'jimOrders' function below.
     *
     * The function is expected to return an INTEGER_ARRAY.
     * The function accepts 2D_INTEGER_ARRAY orders as parameter.
     */
    
    public static List<Integer> jimOrders(List<List<Integer>> orders) {
    // Write your code here
    
    
    long[] val=new long[orders.size()];
    for(int i=0;i<orders.size();i++){
        long temp=orders.get(i).get(0)+orders.get(i).get(1);
        val[i]=temp*10000 +(i+1);
    
    }
    Arrays.sort(val);
    System.out.println(Arrays.toString(val));
    ArrayList<Integer> list=new ArrayList<>();
    for(long i:val){
        list.add((int)(i%10000));
    }
    
    return list;
    }
    

    }