Hexagonal Grid Discussions | Algorithms | HackerRank
  • + 0 comments

    My python3 example with O(n) complexity:

    def hexagonalGrid(a, b):
        if ((a.count('1') + b.count('1')) % 2 != 0):
            return 'NO'
        white = 0
        block = False
        for i in range(len(a)):
            if (a[i] == '1'):
                if block and white % 2 != 0:
                    return 'NO'
                block = True
            elif (a[i] == '0'):
                block = False
                white += 1
            if (b[i] == '1'):
                if block and white % 2 != 0:
                    return 'NO'
                block = True
            elif (b[i] == '0'):
                block = False
                white += 1          
        return 'YES'