Hexagonal Grid Discussions | Algorithms | HackerRank
  • + 0 comments

    python3,

    def hexagonalGrid(a, b):
        def explore(name, i):
            if name == 'a':
                if i < len(a) and a[i] == 0:
                    a[i] = 1
                    return 1 + explore('b', i) + explore('a', i+1)
            if name == 'b':
                if i < len(b) and b[i] == 0:
                    b[i] = 1
                    return 1 + explore('a', i+1) + explore('b', i+1)
            return 0
    
        a = [int(i) for i in a]
        b = [int(i) for i in b]
    
        for i in range(len(a)):
            cnt = 0
            if a[i] == 0:
                cnt = explore('a', i)
            if b[i] == 0:
                cnt = explore('b', i)
            if cnt % 2 != 0:
                return "NO"
    
        return "YES"