Gridland Metro

  • + 0 comments

    // where i am doing wrong

    public static long gridlandMetro(int n, int m, int k, List<List<Integer>> track) {
        Map<Integer,int[]> realPath = new HashMap<>();
        long result = 0;
        for(int i =0;i<k;i++){
            List<Integer> l1 = track.get(i);
            int row = l1.get(0);
            int c1 = l1.get(1);
            int c2 = l1.get(2);
            if(realPath.containsKey(row)){
                 int[] coloums = realPath.get(row);
                int c21 = coloums[0];
                int c22 = coloums[1];
                if(c21>c1){
                   coloums[0] = c1;
                }
                if(c22<c2){
                    coloums[1] = c2;
                }
                realPath.put(row, coloums);
            }else{
                int[] coloums = new int[2];
                coloums[0] = c1;
                coloums[1] = c2;
                realPath.put(row, coloums);
            }
        }
        for(int i =1;i<=n;i++){
            if(realPath.containsKey(i)){
                int[] coloums = realPath.get(i);
                int c21 = coloums[0];
                int c22 = coloums[1];
                int incr = (m+c21)-(c22+1);
                result+=incr;
            }else{
                result+=m;
            }
        }
        return result;
    }