Sort by

recency

|

372 Discussions

|

  • + 0 comments

    Python3 Solution

    def marking(res, r, c, direction):
        for dr, dc in direction:
            if dr < 0 and r + dr > -1:
                res[r+dr][c] = "."
            if dr > 0 and r + dr < len(res):
                res[r+dr][c] = "."
            if dc < 0 and c + dc > -1:
                res[r][c+dc] = "."
            if dc > 0 and c + dc < len(res[0]):
                res[r][c+dc] = "."
        res[r][c] = "."
            
        return res
                
    def explode(grid):
        row, col = len(grid), len(grid[0])
        direction = [[1, 0], [-1, 0], [0, 1], [0, -1], [0, 0]]
        
        afterGrid = afterGrid = [["O"] * col for i in range(row)]
    
        for i in range(row):
            for j in range(col):
                if grid[i][j] == "O":
                    afterGrid = marking(afterGrid, i, j, direction)
        
        return afterGrid
    
    def bomberMan(n, grid):
        row, col = len(grid), len(grid[0])
        
        if n <= 1:
            return grid
        
        if n % 2 == 0:
            return ["O" * col for i in range(row)]
            
        grid = explode(grid)
     
        if n % 4 == 1:
            grid = explode(grid)
            
        res = []
        
        for line in grid:
            res.append("".join(line))
        
        return res
    
  • + 0 comments

    Here is The bomberman game solution in python, java, c++, c and javascript programming - https://programmingoneonone.com/hackerrank-the-bomberman-game-problem-solution.html

  • + 0 comments

    I have an additional question. What happens exactly in 4, 5, 6, 7 .... second?

    3 second, explosion... and do I place the new bombs then or not?

  • + 0 comments

    Here is problem solution in Python Java c++ c and Javascript - https://programmingoneonone.com/hackerrank-the-bomberman-game-problem-solution.html

  • + 0 comments

    Javascript

    function bomberMan(n, grid) {
        let row = grid.length, column = grid[0].length
        let arr1 = Array.from(Array(grid.length), () => new Array(grid[0].length).fill('O'))
        if (n == 1)
            return grid
        if (n % 2 == 0) {
            for (let i = 0; i < row; i++)
                arr1[i] = arr1[i].join("")
            return arr1
        }
        function boom(cur) {
            let arr = Array.from(Array(row), () => new Array(column).fill('O'));
            for (let r = 0; r < row; r++) {
                for (let c = 0; c < column; c++) {
                    if (cur[r][c] == 'O') {
                        arr[r][c] = "."
                        if (r + 1 < row)
                            arr[r + 1][c] = '.'
                        if (r - 1 >= 0)
                            arr[r - 1][c] = '.'
                        if (c + 1 < column)
                            arr[r][c + 1] = '.'
                        if (c - 1 > -1)
                            arr[r][c - 1] = '.'
                    }
                }
            }
            for (let i = 0; i < row; i++)
                arr[i] = arr[i].join("")
            return arr
        }
        let first = boom(grid)
        let second = boom(first)
        return (n % 4 == 3) ? first : second
    
    }