Customized Chess Board

Sort by

recency

|

36 Discussions

|

  • + 0 comments
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    # Complete the solve function below.
    def solve(board):
        res = []
        p_el = None
        flag = False
        for i in board:
            count = 0
            prv = None
            for j in i:
                if count == 0:
                    if j == p_el:
                        flag = True
                        break
                    else:
                        p_el = j
                count += 1
                if prv == j:
                    flag = True
                    break
                prv = j
            if flag:
                res.append('No')
                break
        if not flag:
            res.append('Yes')
        return res[0]
            
                
                
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        t = int(input().strip())
    
        for t_itr in range(t):
            n = int(input().strip())
    
            board = []
    
            for _ in range(n):
                board.append(list(map(int, input().rstrip().split())))
    
            result = solve(board)
    
            fptr.write(result + '\n')
    
        fptr.close()
    
  • + 0 comments

    My Python approach :

    def solve(board):
        i = 0
        if(board[0][1] == 0):
            check = 0
        else:
            check = 1
        if(len(board) % 2 == 0):
            while(i < len(board)):
                if board[i][i] != (1 - check) or board[i][len(board) - 1 - i] != check:
                    return 'No'
                i += 1
        else:
            while(i < len(board)):
                if board[i][i] != (1 - check) or board[i][len(board)-1-i] != (1 - check):
                    return 'No'
                i += 1    
        i = 0
        while(i < len(board)-1):
            if(board[i][i+1] != check or board[i+1][i] != check):
                return 'No'
            i += 1
        return 'Yes'
    
  • + 0 comments

    test case 0 fails but all the rest passed why ????

  • + 0 comments

    ** C++ solution**

    #include <bits/stdc++.h>
    
    using namespace std;
    
    
    int main()
    
    {
    	int t;
    	cin>>t;
    	while(t>0)
    	{
    		int n,flag=0;
    		cin>>n;
    		int arr[n][n];
    
    		for(int i=0;i<n;i++)
    		{
    			for(int j=0;j<n;j++)
    				cin>>arr[i][j];
    		}
    
    		for(int i=0;i<n;i++)
    		{
    			for(int j=0;j<n-1;j++)
    			{
    				if(arr[i][j]==arr[i][j+1])
    					flag=1;
    			}
    		}
    		if(flag==0)
    			cout<<"Yes"<<endl;
    		else
    			cout<<"No"<<endl;
    		t--;
    
    
    	}
    }
    
  • + 0 comments

    static String solve(List> board) {

        for (int i = 0; i < board.size()-1; i++) {
            List<Integer> row = board.get(i);
            List<Integer> col1 = board.get(i+1);
            int col=0;
            for (int k = 1; k < row.size(); k++) {
                int val = row.get(k);
                if(val==row.get(col)) {
                    return "No";
                }
                else {
                    col++;
                }
            }
    
            for (int k = 0; k < row.size(); k++) {
                int val1=col1.get(k);
                int val = row.get(k);
                if(val==val1) {
                    return "No";
                }
            }
    
    
        }
        return "Yes";
    }