Day - 35
Assalamu alaykum, everyone! Today, I am going to share the 35th day of my coding challenge. I think you like it. If you find it useful, share it with your friends.
So, what kind of problems was solved for today? Let's start!
/*
?* @param {number[][]} grid
?* @return {number}
?*/
var islandPerimeter = function (grid) {
? let queue = [];
? for (let row = 0; row < grid.length; row++) {
? ? for (let col = 0; col < grid[0].length; col++) {
? ? ? if (grid[row][col] === 1) {
? ? ? ? queue.push([row, col]);
? ? ? }
? ? }
? }
? let perimeter = 0;
? let directions = [
? ? [-1, 0],
? ? [1, 0],
? ? [0, -1],
? ? [0, 1],
? ];
? while (queue.length > 0) {
? ? let [curRow, curCol] = queue.shift();
? ? for (let [dr, dc] of directions) {
? ? ? let nRow = curRow + dr;
? ? ? let nCol = curCol + dc;
? ? ? let rowInbounds = 0 <= nRow && nRow < grid.length;
? ? ? let colInbounds = 0 <= nCol && nCol < grid[0].length;
? ? ? if (!rowInbounds || !colInbounds || grid[nRow][nCol] === 0) {
? ? ? ? perimeter++;
? ? ? ? continue;
? ? ? }
? ? }
? }
? return perimeter;
};
That's all. Pay attention for my challenge. I will try to solve more problems every day! Thanks for you time for spending to read my article! See you! Bye!
Hello Abbosbek... We post 100's of job opportunities for developers daily here. Candidates can talk to HRs directly. Feel free to share it with your network. Visit this link - https://jobs.hulkhire.com And start applying.. Will be happy to address your concerns, if any