Skip to content

pwener/hackerrank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang running

Sometimes, the problems don't have a main function to read file, as example:

func main() {
    reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)

    nTemp, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
    checkError(err)
    n := int(nTemp)

    var lines = []int{}

    for {
		input := strings.TrimSpace(readLine(reader))
		if input == "" {
			break
		}

		lTemp, err := strconv.ParseInt(input, 10, 64)
		checkError(err)

		lines = append(lines, int(lTemp))
	}

	Execute(n, lines)
}

func readLine(reader *bufio.Reader) string {
    str, _, err := reader.ReadLine()
    if err == io.EOF {
        return ""
    }

    return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
    if err != nil {
		panic(err)
    }
}

How to run

cat input01.txt | go run main.go 
cat input01.txt | npx ts-node src/foo.ts

About

My hackerrank solutions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published