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

How to Use AWS Nitro Enclaves Attestation Document

How to make the Daily Scrum more engaging?

OOP Design Patterns — Template Method Pattern

Laser and firing— Day 4 of becoming a Game Developer

CS371p: Week 9

Stranger things with Core Data Stacks comparison

IoT Messaging Protocols

Kernel Heap Sort algorithm

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

WHAT IS A COROUTINE?

FeignClients With KotlinCoroutines

How to use groupBy in Reactor

Dagger 2 Dependency Injection Part 1