Last active
June 15, 2021 12:37
-
-
Save brjoaof/d4f89e7365174aa1d81788c7cd280370 to your computer and use it in GitHub Desktop.
HackerRank - Simple Array Sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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