Friday, September 30, 2022
HomeSoftware DevelopmentVerify if any row of the matrix could be transformed to the...

Verify if any row of the matrix could be transformed to the weather current within the goal row


  

import java.util.*;

  

class GFG {

  

    

    

    

    public static boolean checkPossibleOrNot(

        int[][] mat, int[] target)

    {

  

        

        int[] comp = new int[mat[0].length];

  

        

        

        Arrays.fill(comp, Integer.MIN_VALUE);

  

        

        for (int[] val : mat) {

  

            

            

            

            if (val[0] <= target[0]

                && val[1] <= target[1]

                && val[2] <= target[2])

  

                

                comp = new int[] { Math.max(

                                       comp[0], val[0]),

                                   Math.max(

                                       comp[1], val[1]),

                                   Math.max(

                                       comp[2], val[2]) };

        }

  

        

        return Arrays.equals(comp, target);

    }

  

    

    public static void main(String[] args)

    {

        int[][] mat

            = { { 2, 5, 3 }, { 2, 8, 4 }, { 1, 5, 7 } };

        int[] target = { 2, 5, 7 };

  

        String ans = checkPossibleOrNot(

                         mat, target)

                         ? "Yes"

                         : "NO";

        System.out.println(ans);

    }

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments