package codewar;import java.util.*;public class DirReduction{ public static String[] dirReduc(String[] arr){ Listlist = new ArrayList (); for(String x : arr){ list.add(x); } while(true){ int len = list.size(); for(int I = 0; I < list.size() - 1; i++){ if("NORTH".equals(list.get(i)) && "SOUTH".equals(list.get(i+1))|| "SOUTH".equals(list.get(i)) && "NORTH".equals(list.get(i+1))|| "EAST".equals(list.get(i)) && "WEST".equals(list.get(i+1))|| "WEST".equals(list.get(i)) && "EAST".equals(list.get(i+1))){ list.remove(i); list.remove(i); break; } } if( len == list.size()){ break; } } return list.toArray(new String[0]); }}