Permuting Two Arrays

Sort by

recency

|

135 Discussions

|

  • + 0 comments
    def twoArrays(k, A, B):
        A =  sorted(A, reverse=True)
        B =  sorted(B)
        
        for i, num in enumerate(A):
            if A[i] + B[i] < k:
                return 'NO'
        
        return 'YES'
    
  • + 0 comments

    Python 3 solutions:

    import functools
    import typing
    
    
    def twoArrays(k: int, A: list[int], B: list[int]) -> typing.Literal["NO", "YES"]:
        A.sort()
        B.sort(reverse=True)
        return "NO" if any(a + b < k for a, b in zip(A, B, strict=True)) else "YES"
    
    
    def twoArrays(k: int, A: list[int], B: list[int]) -> typing.Literal["NO", "YES"]:
        @functools.lru_cache
        def cached_helper(ab: tuple[int, int]) -> bool:
            return sum(ab) < k
    
        A.sort()
        B.sort(reverse=True)
        return "NO" if any(map(cached_helper, zip(A, B, strict=True))) else "YES"
    
    
    
    # 88
    s=sorted;twoArrays=lambda k,A,B:["YES","NO"][any(a+b<k for a,b in zip(s(A),s(B)[::-1]))]
    
  • + 0 comments
    def twoArrays(k, A, B):
        A.sort()
        B.sort(reverse=True)
        for i in range(len(A)):
            if A[i] + B[i] < k:
                return "NO"
        return "YES"
    
  • + 0 comments

    Rust solution:

    fn twoArrays(k: i32, A: &mut [i32], B: &mut [i32]) -> String {
        A.sort();
        B.sort();
        
        for (a, b) in A.iter().zip(B.iter().rev()) {
            if a + b < k {
                return "NO".to_string();
            }
        }
        
        "YES".to_string()
    }
    
  • + 0 comments

    Anyone getting a

    Solution.go:10:5: package slices is not in GOROOT (/usr/local/go/src/slices)

    while trying to solve in Go?

    I'm working with 1.22.1 support for but slices should be there since 1.8, as far as i understand