Birthday Cake Candles Solution in Kotlin — Hackerrank

candles = [4,4,1,3]
  • int candles[n]: the candle heights
  • int: the number of candles that are tallest
  • The first line contains a single integer, n , the size of candles[].
  • The second line contains n space-separated integers, where each integer i describes the height of candles[i].
4 
3 2 1 3
6

fun birthdayCakeCandles(candles: Array<Int>): Int {
// Write your code here
var max = candles.max()!!.toLong()
var total = 0
for (x in 0 until candles.size) {
val it = candles[x].toLong()
if (it == max) {
total++
}
}

return total
}

--

--

--

Hey curious person, I am Software Developer

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

Recommended from Medium

Your First Pandoc Book Template

Cheatsheet for NumPy: Essential and Lesser-Known Functions

Numpy python

Soccer Expected Goals — Data Extraction — Part-One: Extracting Shots Data

Using Lambda Expressions in your Java Code.

My (Coding Journey So Far

Is Project Planning An Imposture?

Why the coding interview is ineffective

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

Transformations in encapsulated LiveData

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

How we might delegate the handling of Ads to our Chromecast receiver

Coroutine Adventure Part.4