chore: add hackerrank solutions
Some checks failed
Go Bump / bump (push) Failing after 6s
Go Test / build (push) Successful in 47s

This commit is contained in:
xuu
2024-10-26 12:03:06 -06:00
parent 3c9af95ec4
commit 04bbac8559
18 changed files with 1169 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
"strings"
)
/*
* Complete the 'flippingBits' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts LONG_INTEGER n as parameter.
*/
func flippingBits(n int64) int64 {
// Write your code here
max := int64(^uint32(0))
return n ^ max
}
func main() {
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
checkError(err)
defer stdout.Close()
writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)
qTemp, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
checkError(err)
q := int32(qTemp)
for qItr := 0; qItr < int(q); qItr++ {
n, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
checkError(err)
result := flippingBits(n)
fmt.Fprintf(writer, "%d\n", result)
}
writer.Flush()
}
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)
}
}