From 0522c9f1b8e66bebc08874ac91aaaf2a3938a364 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Thu, 8 May 2025 19:22:02 -0400 Subject: [PATCH] [Hacker Rank] Interview Preparation Kit: Dictionaries and Hashmaps: Two Strings. Documentation added. --- .../two-strings-solution-notes.md | 14 ++++ .../dictionaries_and_hashmaps/two-strings.md | 80 +++++++++++++++++++ .../dictionaries_and_hashmaps/two_strings.go | 3 +- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings-solution-notes.md create mode 100644 docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings.md diff --git a/docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings-solution-notes.md b/docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings-solution-notes.md new file mode 100644 index 0000000..b08a035 --- /dev/null +++ b/docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings-solution-notes.md @@ -0,0 +1,14 @@ +# [Two Strings](https://www.hackerrank.com/challenges/two-strings) + +- Difficulty: `#easy` +- Category: `#ProblemSolvingBasic` `#dictionaries` `#hashmaps` + +## Clarification + +The problem asks to find if there is a substring between 2 words, +it does not require finding a particular one that meets a certain property, +not counting all the possible ones. + +With that in mind, simply find the first 1-letter intersection between two word +to return "YES". +The worst case is to return "NO" after going through both words letter by letter. diff --git a/docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings.md b/docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings.md new file mode 100644 index 0000000..66fda37 --- /dev/null +++ b/docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings.md @@ -0,0 +1,80 @@ +# [Two Strings](https://www.hackerrank.com/challenges/two-strings) + +- Difficulty: `#easy` +- Category: `#ProblemSolvingBasic` `#dictionaries` `#hashmaps` + +Given two strings, determine if they share a common substring. +A substring may be as small as one character. + +## Example + +`s1 = 'and'` +`s1 = 'art'` + +These share the common substring `a`. + +`s1 = 'be'` +`s1 = 'cat'` + +These do not share a substring. + +## Function Description + +Complete the function twoStrings in the editor below. + +twoStrings has the following parameter(s): + +- `string s1`: a string +- `string s2`: another string + +## Returns + +- `string`: either YES or NO + +## Input Format + +The first line contains a single integer , the number of test cases. + +The following pairs of lines are as follows: + +The first line contains string `s1`. +The second line contains string `s2`. + +## Constraints + +- `s1` and `s2` consist of characters in the range ascii[a-z]. +- $ 1 \leq p \leq 10 $ +- $ 1 \leq |s1|, |s2| \leq 10^5 $ + +## Output Format + +For each pair of strings, return `YES` or `NO`. + +## Sample Input + +```text +2 +hello +world +hi +world +``` + +## Sample Output + +```text +YES +NO +``` + +## Explanation + +We have pairs to check: + +1. `s1 = "hello"`, `s2 = "world"`. The substrings `"o"` and `"l"` +are common to both strings. +2. `a = "hi"`, `b = "world"`. `s1` and `s2` share no common substrings. + +## Appendix + +[Solution notes](two-strings-solution-notes.md) diff --git a/exercises/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.go b/exercises/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.go index 8369587..d558f10 100644 --- a/exercises/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.go +++ b/exercises/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.go @@ -1,5 +1,6 @@ /** - * @link Problem definition [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.md]] + * @link Problem definition [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings.md]] + * @see Solution Notes [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings-solution-notes.md]] */ package hackerrank