Sort by

recency

|

34 Discussions

|

  • + 0 comments

    the problem is resolution

    using System; using System.Collections.Generic; using System.IO; using System.Linq;

    class Solution { static void Main(string[] args) { // Read the input string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]);

        int[] firstRow = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    
        // Call the method to compute the last row
        int[] lastRow = XorMatrix(n, m, firstRow);
    
        // Print the result
        Console.WriteLine(string.Join(" ", lastRow));
    }
    
    static int[] XorMatrix(int n, int m, int[] firstRow)
    {
        int[] previousRow = firstRow;
        int[] currentRow = new int[n];
    
        // Generate each row from the second to the last row
        for (int i = 1; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                currentRow[j] = previousRow[j] ^ previousRow[(j + 1) % n];
            }
    
            // Update the previous row to the current row for the next iteration
            previousRow = (int[])currentRow.Clone();
        }
    
        // The last generated row is stored in previousRow
        return previousRow;
    }
    

    }

  • + 0 comments

    Code does not compile.

  • + 0 comments

    Here is XOR matrix problem solution in Python Java c++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-xor-matrix-problem-solution.html

  • + 0 comments

    Getting this error:

    Solution.java:55: error: cannot find symbol for (int resultItr = 0; resultItr < result.length; resultItr++) { ^ symbol: variable result location: class Solution Solution.java:56: error: cannot find symbol bufferedWriter.write(String.valueOf(result[resultItr])); ^ symbol: variable result location: class Solution Solution.java:58: error: cannot find symbol if (resultItr != result.length - 1) { ^ symbol: variable result location: class Solution 3 errors

  • + 0 comments

    here is the first version, even main() has been corrected :

    public class Solution {
    
        /*
         * Complete the xorMatrix function below.
         */
        static int[] xorMatrix(long m, int[] first_row) {
             
             int n = first_row.length;
             int save0;
             
             for( long i=1; i<m; i++){
                save0 = first_row[0];
                for( int j=0; j < n-1; j++){
                   first_row[j] = first_row[j] ^ first_row[j+1];
                }            
                first_row[n-1] = first_row[n-1] ^ save0;
             }
             
             return first_row;
             
    
        }
    
        private static final Scanner scanner = new Scanner(System.in);
    
        public static void main(String[] args) throws IOException {
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
    
            String[] nm = scanner.nextLine().split(" ");
    
            int n = Integer.parseInt(nm[0].trim());
    
            long m = Long.parseLong(nm[1].trim());
    
            int[] first_row = new int[n];
    
            String[] first_rowItems = scanner.nextLine().split(" ");
    
            for (int first_rowItr = 0; first_rowItr < n; first_rowItr++) {
                int first_rowItem = Integer.parseInt(first_rowItems[first_rowItr].trim());
                first_row[first_rowItr] = first_rowItem;
            }
    
            int[] result = xorMatrix(m, first_row);
    
            for (int resultItr = 0; resultItr < result.length; resultItr++) {
                bufferedWriter.write(String.valueOf(result[resultItr]));
    
                if (resultItr != result.length - 1) {
                    bufferedWriter.write(" ");
                }
            }
    
            bufferedWriter.newLine();
    
            bufferedWriter.close();
        }
    }