2906. Construct Product Matrix || Leetcode Weekly Contest 367

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

nice solution, however, i had a doubt, my approach was that i calculated the entire product of the matrix and then performed division operation for each (i, j) pair and it resulted in TLE, have you tried this ?? if yes, then what do you think can be a reason for that

VivekSingh-otlk
Автор

Why This Solution Not Passes All TestCases I know this is not optimize but not Logically incorrect


public int[][] grid) {


long pro = 1;

for(int i=0;i<grid.length;i++){
for(int j=0;j<grid[0].length;j++){
pro = pro * (long) grid[i][j];

}
}

int res[][] = new
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[0].length; j++) {
if (grid[i][j] != 0) {
// Divide the total product by the current element and take modulus
res[i][j] = (int)((pro / grid[i][j]) % 12345);
} else {
// Handling zero elements
res[i][j] = (int)(pro % 12345);
}
}
}

return res;




}

adityamaurya
join shbcf.ru