Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

632
Views
HackerRank says ~ no response on stdout ~ Swift

I'm taking a course with a hands-on question on Swift programming, that redirect me to Hackerrank

Write a function named printMessage that takes two parameters - a string message and an integer count. The message should print and repeat the message as specified in the count parameter.

Message:"Hello , How are You"

For instance take Count as 8

This should print Message:"Hello , How are You" 8 times consecutively.

The problem is when I submit my code always said Wrong answer, then I tried with custom input, and it throws me no response on STDOUT. Anyone knows what's wrong?

import Foundation 

func printMessage(message: String, count: Int) {

    for _ in 0..<count {
        print(message)

    }
}

let message: String = readLine()!
let count: Int = Int(readLine()!)!
printMessage(message: message, count: count)
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I have run into this before, the way I solved it was saving my code somewhere and resetting to the boilerplate code. So just reset to the boilerplate and copy your function back in. On many swift hackerrank problems they have something like the following:

func myFunc(param: [Int]) -> [Int] {
    /*
    * Write your code here.
    */
}

// The following is an example of your function being written to stdout

let fileName = ProcessInfo.processInfo.environment["OUTPUT_PATH"]!
FileManager.default.createFile(atPath: fileName, contents: nil, attributes: nil)
let fileHandle = FileHandle(forWritingAtPath: fileName)!

let result = myFunc(param: input)

fileHandle.write(result.map{ String($0) }.joined(separator: "\n").data(using: .utf8)!)
fileHandle.write("\n".data(using: .utf8)!)

The code after the function is what writes to stdout

over 4 years ago · Santiago Trujillo Report

0

Hackerrank in some swift exercises fires that message whenever you have a buffer overflow, instead of warning you about it

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!