Hexagonal Grid Discussions | Algorithms | HackerRank

Sort by

recency

|

38 Discussions

|

  • + 0 comments

    Show appreciation with unique corporate gifts like a "Hexagonal Grid" while fostering creativity and innovation. These gifts inspire collaboration and problem-solving skills, ideal for team-building activities or office decor. Enhance workplace dynamics with thoughtful items that encourage productivity and aesthetic appeal. Whether used for brainstorming sessions or as a decorative element, Hexagonal Grids symbolize forward-thinking and synergy within your organization. Elevate your corporate culture with meaningful gifts that reflect your commitment to excellence and teamwork.

  • + 0 comments

    ~10 lines Python, 100%, cool bit things

    If you figure out what the numbers mean I'll buy you a virtual coffee :D

    @cache
    def f(a,b):
        x=((a&3)<<2)|(b&3)
        if a==b:
            return True
        if (a,b)==(0,1) or (a,b)==(1,0) or x in {6,11,14}:
            return False
        if x in {2,7,8,13}:
            return f(a>>1,b>>1)
        if x in {0,3,5,9,10,12,15}:
            return f(a>>2,b>>2)
        return f(a>>1,(b>>1)|1) or f((a>>1)|1,b>>1)
    
    def hexagonalGrid(a, b):
        return "YES" if f(int(a,2),int(b,2)) else "NO"
    
  • + 0 comments

    Here is Hexagonal Grid problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-hexagonal-grid-problem-solution.html

  • + 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'
    
  • + 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"