Skip to content

Instantly share code, notes, and snippets.

@brjoaof
Last active June 15, 2021 12:37
Show Gist options
  • Save brjoaof/d4f89e7365174aa1d81788c7cd280370 to your computer and use it in GitHub Desktop.
Save brjoaof/d4f89e7365174aa1d81788c7cd280370 to your computer and use it in GitHub Desktop.
HackerRank - Simple Array Sum
// https://www.hackerrank.com/challenges/simple-array-sum/problem
import java.io.*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.functions.*
import kotlin.jvm.internal.*
import kotlin.ranges.*
import kotlin.sequences.*
import kotlin.text.*
/*
* Complete the 'simpleArraySum' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY ar as parameter.
*/
fun simpleArraySum(ar: Array<Int>): Int {
var sum = 0
ar.forEach { sum += it }
return sum
}
fun main(args: Array<String>) {
val arCount = readLine()!!.trim().toInt()
val ar = readLine()!!.trimEnd().split(" ").map{ it.toInt() }.toTypedArray()
val result = simpleArraySum(ar)
println(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment