Bill Division Solution in Kotlin -HackerRank

  • bill: an array of integers representing the cost of each item ordered
  • k: an integer representing the zero-based index of the item Anna doesn’t eat
  • b: the amount of money that Anna contributed to the bill
4 1 
3 10 2 9
12
5

fun bonAppetit(bill: Array<Int>, k: Int, b: Int): Unit {
var annaBill = 0for(x in 0 until bill.size) {
val it = bill[x]
if (x != k) {
annaBill += it
}
}

println(
if (annaBill / 2 == b) "Bon Appetit"
else b - annaBill / 2
)
}
4 1 
3 10 2 9
7
Bon Appetit

--

--

--

Hey curious person, I am Software Developer

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

Recommended from Medium

A Playground to become an advance JavaScript developer

React JS — QuizBee App

Create REST API’s with FreePascal

TypeScript, install and say Hello :)

Optional Chaining (?.)

Standardise your npm scripts

Build an Instagram Feed UI Clone with React, Next.js and Tailwind CSS

Let’s A-Synchronize to Synchronize

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

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

Getting… rid of those missing android* source sets warnings on your KMP project

Coroutine Adventure Part.4

Use AWS CodeArtifact in your project.