Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackerrank - Between Two Sets #34

Open
NicolaBernini opened this issue Apr 5, 2020 · 1 comment
Open

Hackerrank - Between Two Sets #34

NicolaBernini opened this issue Apr 5, 2020 · 1 comment
Assignees

Comments

@NicolaBernini
Copy link
Owner

Overview

All about Between Two Sets

@NicolaBernini
Copy link
Owner Author

Scala

import java.io._
import java.math._
import java.security._
import java.text._
import java.util._
import java.util.concurrent._
import java.util.function._
import java.util.regex._
import java.util.stream._
import scala.collection.immutable._
import scala.collection.mutable._
import scala.collection.concurrent._
//import scala.collection.parallel.immutable._
//import scala.collection.parallel.mutable._
import scala.concurrent._
import scala.io._
import scala.math._
import scala.sys._
import scala.util.matching._
import scala.reflect._

object Result {

    /*
     * 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
     */

    def getTotalX(a: Array[Int], b: Array[Int]): Int = {
    // Write your code here
    (for(n <- a.max to b.min) yield {
        (
            (for(e <- a) yield {
                n%e match {
                    case 0 => 1 
                    case _ => 0 
                }
            }).product * 
            (for(e <- b) yield {
                e%n match {
                    case 0 => 1 
                    case _ => 0 
                }
            }).product 
        )
    }).sum
    }
}

object Solution {
    def main(args: Array[String]) {
        val printWriter = new PrintWriter(sys.env("OUTPUT_PATH"))

        val firstMultipleInput = StdIn.readLine.replaceAll("\\s+$", "").split(" ")

        val n = firstMultipleInput(0).toInt

        val m = firstMultipleInput(1).toInt

        val arr = StdIn.readLine.replaceAll("\\s+$", "").split(" ").map(_.trim.toInt)

        val brr = StdIn.readLine.replaceAll("\\s+$", "").split(" ").map(_.trim.toInt)

        val total = Result.getTotalX(arr, brr)

        printWriter.println(total)

        printWriter.close()
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant