Advertisement
saurav_kalsoor

Minimum Moves - KOTLIN

Sep 27th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.44 KB | None | 0 0
  1. package com.company
  2.  
  3. import java.util.*
  4.  
  5.  
  6. fun main() {
  7.     val sc = Scanner(System.`in`)
  8.     val n = sc.nextInt()
  9.     val number = sc.next()
  10.     val result = minimiseMoves(number, n)
  11.     println(result)
  12. }
  13.  
  14.  
  15. fun minimiseMoves(number: String, n: Int): Int {
  16.     var moves = 0
  17.     moves += number[n - 1] - '0'
  18.     for (i in 0 until n - 1) {
  19.         if (number[i] != '0')
  20.             moves += number[i] - '0' + 1
  21.     }
  22.     return moves
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement