Skip to main content

Command Palette

Search for a command to run...

Check if Grid Satisfies Conditions

Published
1 min read
Check if Grid Satisfies Conditions
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is:

  • Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).

  • Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).

Return true if all the cells satisfy these conditions, otherwise, return false.

LeetCode Problem - 3142

class Solution {

    // Method to check if the given grid satisfies certain conditions
    public boolean satisfiesConditions(int[][] grid) {

        // Iterate through each element in the grid
        for(int i = 0; i < grid.length; i++){
            for(int j = 0; j < grid[0].length; j++){

                // Check the condition for the element below the current element
                if(i + 1 < grid.length){
                    if(!(grid[i][j] == grid[i + 1][j])){
                        return false; // Return false if the condition is not met
                    }
                }

                // Check the condition for the element to the right of the current element
                if(j + 1 < grid[0].length){
                    if(!(grid[i][j] != grid[i][j + 1])){
                        return false; // Return false if the condition is not met
                    }
                }

            }
        }

        // Return true if all conditions are satisfied
        return true;
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.