• + 0 comments

    The directions for this challenge were quite confusing for me but this is how I solved it in c#

    {
        /*
         * Complete the 'getTotalX' function below.
         *
         * The function is expected to return an INTEGER.
         * The function accepts following parameters:
         *  1. INTEGER_ARRAY a
         *  2. INTEGER_ARRAY b
         */
    
        public static int getTotalX(List<int> a, List<int> b)
        {
            var start = a.Min();        
            var end = b.Max();
            var count = 0;
            for (var i = start; i <= end; i++)
            {
                if (a.areAllFactorsOf(i) && b.areAllMultiplesOf(i))
                    count++;
            }
            return count;
        }
    
        public static bool areAllMultiplesOf(this List<int> values, int target)
        {
            return values.All(v => v % target == 0);
        }
    
        public static bool areAllFactorsOf(this List<int> values, int target)
        {
            return values.All(v => target % v == 0);
        }
    }