Kangaroo Number Line Jumps Solution in Kotlin — HackerRank

  • The first kangaroo starts at location x1 and moves at a rate of v1 meters per jump.
  • The second kangaroo starts at location x2 and moves at a rate of v2 meters per jump.
  • x1, v1: integers, starting position and jump distance for kangaroo 1
  • x2, v2: integers, starting position and jump distance for kangaroo 2
0 3 4 2
YES
fun kangaroo(x1: Int, v1: Int, x2: Int, v2: Int): String {

val distance = x2-x1
val jump = v1-v2

if (v1>v2 && distance % jump == 0) {
return "YES"
} else {
return "NO"
}
}

--

--

--

Hey curious person, I am Software Developer

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

Recommended from Medium

Beyond Code — Contributing to Community Spirit

Learn Unity Editor Scripting: Editor Windows (Part 5)

4 Common Challenges faced by NDIS Service Providers

Laptop Local: A DevOps Oriented Workflow for Mac OS (X)

[LeetCode]#1290. Convert Binary Number in a Linked List to Integer

Don’t stop believing: The fall and rise of a tech forum

12. Hard Coding Issues — Part 2

A simple crowdsensing application using accelerator sensor and ThingsBoard

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

How I made an App that Translates Cat Sounds to Human Language

Transformations in encapsulated LiveData

Publishing an anti-bikeshedding money library to Maven Central

Enable Smile serialization on requests using Spring WebClient (Kotlin)