We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/* * Complete the 'beautifulDays' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER i * 2. INTEGER j * 3. INTEGER k */funbeautifulDays(i:Int,j:Int,k:Int):Int{// Write your code herefunInt.reverse():Int{valreversedText="$this".toList().asReversed().joinToString(separator="")if(reversedText.startsWith("0")){returnreversedText.substring(1,reversedText.length).toInt()}returnreversedText.toInt()}funisBeautiful(day:Int):Boolean{valdividend=day.reverse().let{reversedDay->if(reversedDay>day){reversedDay-day}else{day-reversedDay}}valdivision:Double=dividend/k.toDouble()returndivision%1.0==0.0}varresult=0for(dayini..j){if(isBeautiful(day)){result++}}returnresult}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Days at the Movies
You are viewing a single comment's thread. Return to all comments →
Here is my answer in Kotlin: