Sort by

recency

|

3054 Discussions

|

  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-between-two-sets-problem-solution.html

  • + 1 comment

    I'm having trouble understanding the problem here. The explanation is extremely detailed, but I'm not 100% sure how you take 2 and 6 and end up with 6 and 12, and then 2 numbers. Very confusing explanation.

    • + 0 comments

      I am confused by the question too. Let me try to rephrase. Given array A and array B of integers. Find length of answers where an answer is BOTH (i) factorized by all elements of A which means it is a common multiple of elements of A (ii) is a factor of elements of B

      Example: a = [2, 6] b = [24, 36] aMultiple = [6, 12, 18, 24] answer = [6, 12] Example: a = [2, 4] b = [16, 32, 96] aMultiple = [4, 8, 12, 16] answer = [4, 8, 16]

  • + 0 comments

    JavaScript

    function getTotalX(a, b) {
    
      function findGcd(x, y) {
        while (y) {
          [x, y] = [y, x % y];
        }
        return x;
      }
    
      function findLcm(x, y) {
        return (x * y) / findGcd(x, y);
      }
    
      let lcm = a.reduce((acc, val) => findLcm(acc, val));
    
      let gcd = b.reduce((acc, val) => findGcd(acc, val));
    
      let count = 0;
      for (let i = lcm; i <= gcd; i += lcm) {
        if (gcd % i === 0) {
          count++;
        }
      }
    
      return count;
    }
    
  • + 3 comments

    Here is problem solution in Python Java C++ C and Javascript - https://programmingoneonone.com/hackerrank-between-two-sets-problem-solution.html

    • + 0 comments

      Oh, very clean!

  • + 0 comments

    additional code to restrict range based on inputs instead of 1 to 100; int startRange = a.get(a.size()-1); int endRange = b.get(0); for more Visit this website