diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 50e5f0e..86d8ac2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -8,6 +8,7 @@ Every name is sorted in alphabetically. - [danhenriquesc](https://github.com/danhenriquesc) - [hundredrab](https://github.com/hundredrab) - [jackey8616](https://github.com/jackey8616) +- [mateusguerra](https://github.com/mateusguerra) - [mirianashvili](https://github.com/mirianashvili) - [Obsinqsob01](https://github.com/Obsinqsob01) - [PyPatel](https://github.com/PyPatel) diff --git a/README.md b/README.md index 13dd444..dacdf77 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ https://www.hackerrank.com/contests/code-and-the-curious/challenges | Alternating Characters | ✓ | | | | String Construction | | | ✓ | | Ashton and String | | ✓ | | -| Two Strings | | | ✓ | +| Two Strings | ✓ | | ✓ | **Sorting** diff --git a/algorithms/strings/two_strings.py b/algorithms/strings/two_strings.py new file mode 100644 index 0000000..68e50c0 --- /dev/null +++ b/algorithms/strings/two_strings.py @@ -0,0 +1,27 @@ +#!/bin/python3 + +import os + +# Complete the twoStrings function below. +def twoStrings(s1, s2): + intersection = set(s1) & set(s2) + if len(intersection) > 0: + return "YES" + return "NO" + + +if __name__ == '__main__': + fptr = open(os.environ['OUTPUT_PATH'], 'w') + + q = int(input()) + + for q_itr in range(q): + s1 = input() + + s2 = input() + + result = twoStrings(s1, s2) + + fptr.write(result + '\n') + + fptr.close() diff --git a/data_structures/arrays/left_rotation.go b/data_structures/arrays/left_rotation.go new file mode 100644 index 0000000..cbde381 --- /dev/null +++ b/data_structures/arrays/left_rotation.go @@ -0,0 +1,76 @@ +package main + +import ( + "bufio" + "fmt" + "io" + "os" + "strconv" + "strings" +) + +// Complete the rotLeft function below. +func rotLeft(a []int32, d int32) []int32 { + return append(a[d:], a[:d]...) +} + +func main() { + reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024) + + stdout, err := os.Create(os.Getenv("OUTPUT_PATH")) + checkError(err) + + defer stdout.Close() + + writer := bufio.NewWriterSize(stdout, 1024 * 1024) + + nd := strings.Split(readLine(reader), " ") + + nTemp, err := strconv.ParseInt(nd[0], 10, 64) + checkError(err) + n := int32(nTemp) + + dTemp, err := strconv.ParseInt(nd[1], 10, 64) + checkError(err) + d := int32(dTemp) + + aTemp := strings.Split(readLine(reader), " ") + + var a []int32 + + for i := 0; i < int(n); i++ { + aItemTemp, err := strconv.ParseInt(aTemp[i], 10, 64) + checkError(err) + aItem := int32(aItemTemp) + a = append(a, aItem) + } + + result := rotLeft(a, d) + + for i, resultItem := range result { + fmt.Fprintf(writer, "%d", resultItem) + + if i != len(result) - 1 { + fmt.Fprintf(writer, " ") + } + } + + fmt.Fprintf(writer, "\n") + + 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) + } +}