In this post, we will solve **Jumping Bunnies HackerRank Solution**. This problem **(Jumping Bunnies)** is a part of **HackerRank Functional Programming** series.

**Task**

Bunnies are very cute animals who likes to jump a lot. Every bunny has his own range of jump. Lets say there areÂ * N*Â bunnies andÂ

*i*^{th}**(**Â bunny jumpsÂ

*i*âˆˆ [1,*N*])*Â units. Consider a 1-D plane, where initially bunnies are atÂ*

**j**_{i}**0**. All of them starts jumping in forward direction.

For example, consider the case ofÂ ** k^{th}**Â bunny. Initially he is atÂ

**0**. After first jump, he will be at pointÂ

**. After second, he will be atÂ**

*j*_{k}**2 x**Â and so on. AfterÂ

*j*_{k}*Â jump, he will be at pointÂ*

**m**^{th}**.**

*m*x*j*_{k}Two bunnies can only meet each other when they are on the ground. When on the ground, a bunny can wait any amount of time. Being a social animal, all of them decide to meet at the next point where *all* of them will be on the ground. You have to find the nearest point where all the bunnies can meet.

For example, if there areÂ ** N = 3**Â bunnies whereÂ

**,Â**

*j*_{1}= 2**,Â**

*j*_{2}= 3**. Nearest point where all bunnies can meet again is atÂ**

*j*_{3}= 4**12**. First bunny has to jump six times, for second it isÂ

**4**Â times and for third it isÂ

**3**Â times.

Help bunnies to find the nearest point where they can meet again.

**Input Format**

First line will contain an integer,Â * N*, representing the number of bunnies. Second line will containÂ

*Â space separated integer,Â*

**N****,**

*j*_{1}*,*

**j**_{2}**representing the jumping distance of them.**

*. . . j*_{N},**Output Format**

Print the nearest location where all bunnies can meet again.

**Constraints**

**2 <=***N*<= 10**1 <=***j*<= 10_{i}^{6}- For each test case it is guaranteed that solution will not exceedÂ
**2 x 10**.^{18}

**Sample Input #00**

```
3
2 3 4
```

**Sample Output #00**

`12`

**Sample Input #01**

```
2
1 3
```

**Sample Output #01**

`3`

**Explanation**

*Sample Case #00:*Â This is the same example mentioned in the statement above.*Sample Case #01:*Â First bunny has to jumpÂ **3**Â times to pointÂ **3**, whereas second bunny has to jump only one time to go at pointÂ . PointÂ **3**Â will serve as their meeting point.

**Solution – Jumping Bunnies – HackerRank Solution**

**Scala**

import java.util.Scanner object Solution { @scala.annotation.tailrec def gcd(a: Long, b: Long): Long = if (b == 0) a else gcd(b, a % b) def lcm(a: Long, b: Long): Long = a / gcd(a, b) * b def main(args: Array[String]): Unit = { val sc = new Scanner(System.in) val t = sc.nextInt println((0 until t).map(_ => sc.nextLong).reduce(lcm)) } }

**Note: **This problem **(Jumping Bunnies)** is generated by **HackerRank **but the solution is provided by **CodingBroz**. This tutorial is only for **Educational** and **Learning** purpose.