Zocdoc Interview Question: Nothing too unexpected. It se... | Glassdoor

Interview Question

Software Engineer Interview New York, NY

Nothing too unexpected. It seems like "sort a list based on

  the order of another list" is a very popular question there.
Tags:
algorithm
Answer

Interview Answer

1 Answer

0

public static void foo(){
    // Sort data based on order
    final int[] data=new int[]{1,2,3,4,5,6};
    Integer[] order = new Integer[]{4,3,6,2,1,7};

    Arrays.sort(order, new Comparator() {
        public int compare(Integer idx1, Integer idx2) {
            return data[idx1] - data[idx2];
        }
    });
}

Anonymous on May 22, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.