Between Two Sets Solution in Kotlin -HackerRank

  1. The elements of the first array are all factors of the integer being considered
  2. The integer being considered is a factor of all elements of the second array
  • a: an array of integers
  • b: an array of integers
  • The second line contains distinct space-separated integers describing a[i] where 0<i<n.
  • The third line contains m distinct space-separated integers describing b[j] where 0<j<m.
2 3 
2 4
16 32 96
3

fun
getTotalX(a: Array<Int>, b: Array<Int>): Int {
var total = 0 for (x in 1..100) {
var status = true
for
(i in 0 until b.size) {
val it = b[i]
if (it % x != 0) {
status = false
break
}
}
if (status) {
for (i in 0 until a.size) {
val it = a[i]
if (x % it != 0) {
status = false
break
}
}
}
if (status) {
total++
}
} return totat}
  • 2 and 4 divide evenly into 4, 8, 12 and 16.
  • 4, 8 and 16 divide evenly into 16, 32, 96.
  • 4, 8 and 16 are the only three numbers for which each element of a is a factor and each is a factor of all elements of b.

--

--

--

Hey curious person, I am Software Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What happens when you type `ls -l *.c` in the shell

Basic Intro to ggplot2/plotnine for Data Scientists — Scatterplots Ver.

Bitspawn Bi-Weekly Progress Report: July 14th — July 28th 2021

Learn To Model a Double Twisted Tower in Grasshopper

Stable Dependencies Principle (SDP)

CS373 Fall 2021: Adeet Parikh

Exploring The Pillars Of An AWS Well-Architected Framework

Hosting Your Laravel App on Heroku

Clouds

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Umar Syaid Himawan

Umar Syaid Himawan

Hey curious person, I am Software Developer

More from Medium

Use AWS CodeArtifact in your project.

Ideas and Solutions for Advent of Code 2021 in Kotlin — Part 3/4

Kotlin⚡️: Constructors | Erselan Khan

Coroutine - async concurrency in certain order