Sort by

recency

|

370 Discussions

|

  • + 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
    
    }
    
  • + 0 comments

    python

    def bomberMan(n, grid):
        # Write your code here
        if n == 1:
            return grid
        
        if n % 2 == 0:
            return ['O'*c for i in range(r)]
    
        def detonate_bombs(grid):
            new_grid = [['O']*c for i in range(r)]
            
            for i in range(r):
                for j in range(c):
                    if grid[i][j] == 'O':
                        new_grid[i][j] = '.'
                        for x, y in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
                            if 0<=x<r and 0<=y<c:
                                new_grid[x][y] = '.'
                                
            return [''.join(row) for row in new_grid]
        
        n //= 2
        for _ in range((n + 1) % 2 + 1):
            new_grid = detonate_bombs(grid)
            grid = new_grid
            
        return [''.join(row) for row in grid]
    
  • + 0 comments

    N(nothing) only happens at 2 seconds. After that bombs are detonating or you are planting bombs.

    P0->N->P1->D0->P2->D1->P3->D2->P4->D3->....etc

    The question tells you this indirectly as the "nothing" is step 2, and we are told to repeat step 3 and 4. Insulation types for hot climates