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].
3 2 1 3

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) {

return total




Hey curious person, I am Software Developer

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

Recommended from Medium

Learning on the Job

Automating S3 + CloudFront CDN Using PHP



TypeScript, from skeptic to convert

Online Notes — On Paper

Tips on using Android Studio to develop Flutter apps

Learning C++: Boolean Operators

Point & to Move in Unity — Part 4: Fix Player Clipping Objects

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

Tried making bubbles

Learn Kotlin -Null Safety

Collect Kotlin’s Flow Lifecycle Aware With Style

An image of a waterfall.

Why Jetpack data store?