# Birthday Cake Candles Solution in Kotlin — Hackerrank

**Problem **You are in charge of the cake for a child’s birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

**Example**

`candles = [4,4,1,3]`

The maximum height candles are 4 units high. There are 2 of them, so return 2.

**Function Description**

Complete the function **birthdayCakeCandles **in the editor below.

birthdayCakeCandles has the following parameter(s):

- int candles[n]: the candle heights

**Returns**

- int: the number of candles that are tallest

**Input Format**

- The ﬁrst line contains a single integer,
, the size of*n***candles[]**. - The second line contains
space-separated integers, where each integer*n*describes the height of*i***candles[i]**.

**Sample Input**

`4 `

3 2 1 3

**Sample Output**

`6`

**ANSWER**

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}

**Explanation**

Candle heights are **[3, 2, 1, 3]**. The tallest candles are **3** units, and there are **2 **of them.