LeetCode-Feedback / LeetCode-Feedback

664 stars 318 forks source link

[BUG] - 2061. Number of Spaces Cleaning Robot Cleaned. Missing test case #22276

Closed dimaANDandrey closed 4 months ago

dimaANDandrey commented 4 months ago

LeetCode Username

qwertylovekg

Problem Number, Title, and Link

  1. Number of Spaces Cleaning Robot Cleaned https://leetcode.com/problems/number-of-spaces-cleaning-robot-cleaned/description/

Bug Category

Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)

Bug Description

For the test case [[0,0,0],[0,1,1],[0,0,0]], the return value is 3

Language Used for Code

Go

Code used for Submit/Run operation

var (
    directions = [][]int{
        {0, 1}, {1, 0}, {0, -1}, {-1, 0},
    }

    visited map[[3]int]struct{}
    cleaned map[[2]int]struct{}
)

func impl(room [][]int, i, j, direction int) {
    pair := [3]int{i, j, direction}
    if _, exist := visited[pair]; exist {
        return
    }

    visited[pair] = struct{}{}
    cleaned[[2]int{i, j}] = struct{}{}

    nextI, nextJ := i + directions[direction][0], j + directions[direction][1]
    if nextI < 0 || nextI >= len(room) || nextJ < 0 || nextJ >= len(room[i]) || room[nextI][nextJ] != 0 {
        nextI, nextJ = i, j
        direction = (direction + 1) % 4
    }

    impl(room, nextI, nextJ, direction)
}

func numberOfCleanRooms(room [][]int) int {
    visited = make(map[[3]int]struct{}, len(room) * len(room))
    cleaned = make(map[[2]int]struct{}, len(room) * len(room))

    impl(room, 0, 0, 0)

    return len(cleaned)
}

Expected behavior

Expected that the cleaning robot will return to cell 0 0 after moving to the end towards the right and then going downwards, ultimately cleaning 7 cells

Screenshots

No response

Additional context

No response

exalate-issue-sync[bot] commented 4 months ago

Joyce_Ndisya commented: Hello there,

Thank you for reaching out to us.

Kindly provide us with the code or the test case that fails, as the ones you provided were AC upon submission.

Looking forward to your response.

Best, Joyce