Hello World N Times – HackerRank Solution

In this post, we will solve Hello World N Times HackerRank Solution. This problem (Hello World N Times) is a part of HackerRank Functional Programming series.

Task

Print “Hello World” N amount of times. The input portion will be handled automatically. You need to write a function with the recommended method signature.

Input Format

A single line of input containing integer N, the number of times to print “Hello World”.

Output Format

Output N lines, each containing “Hello World”.

Constraints

  • 0 <= N <= 50

Sample Input

4

Sample Output

Hello World
Hello World
Hello World
Hello World

Recommended Method Signature

Number Of Parameters: 1
Parameters: [n]
Returns: nil

For Hackers Using Clojure

This will be the outline of your function body (fill up the blank portion marked by underscores):

 (fn[n]___________________________)

For Hackers Using Scala

This will be the outline of your function body (fill up the blank portion marked by underscores):

 def f(n: Int) = ______________________

For Hackers Using Haskell

 hello_worlds n = ______________________

This will be the outline of your function body (fill up the blank portion marked by underscores):

For Hackers Using other Languages

You have to read input from standard input and write output to standard output. Please follow the input/output format mentioned above.

NOTE: You only need to submit the code above, after filling in the blanks appropriately. The input and output section will be handled by us. The focus is on writing the correct function.

Solution – Hello World N Times – HackerRank Solution

Scala

object Solution extends App {
def f(n: Int): Unit = {
  (0 until n).foreach(_ => println("Hello World"))
}



  var n = scala.io.StdIn.readInt
  f(n)
}

Note: This problem (Hello World N Times) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *