• + 0 comments

    4 line Python, 100%

    Low constraints allow to check all possible sums.

    def _indianJob(g, arr):
        s, sums = sum(arr), [1] + [0] * 10000
        for i in arr:
            sums = sums[0:i] + [sums[x] or sums[x-i] for x in range(i,s+1)]
        return any([i<=g and s-i<=g for i in [i for i in range(s+1) if sums[i]]])
            
    
    def indianJob(g, arr):
        return "YES" if _indianJob(g, arr) else "NO"