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

Kafka KStream Joins for Json Objects

How EVM opcodes run in SputnikVM(RUST) — part 1

The Most Effective TDD

Hop Through Ruby Nested Data Structures (A .each walk through)

5 Tips for Getting More Out of Our Tests

Graph Mining: Introducing Graphs: Learn by finding answers to the following questions?

Bymas replaces olofmeister in FaZe Clan CS:GO Roster

img

Open source projects and the short of time

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

Organizing dependencies with version catalogs in gradle

How to get started with Kotlin Language(Part1).

Primer for String on Java/Kotlin

Gradle version catalogs for an awesome dependency management

El Ateneo Grand Splendid Bookshop