File tree Expand file tree Collapse file tree 3 files changed +96
-1
lines changed
docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps
exercises/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps Expand file tree Collapse file tree 3 files changed +96
-1
lines changed Original file line number Diff line number Diff line change
1
+ # [ Two Strings] ( https://www.hackerrank.com/challenges/two-strings )
2
+
3
+ - Difficulty: ` #easy `
4
+ - Category: ` #ProblemSolvingBasic ` ` #dictionaries ` ` #hashmaps `
5
+
6
+ ## Clarification
7
+
8
+ The problem asks to find if there is a substring between 2 words,
9
+ it does not require finding a particular one that meets a certain property,
10
+ not counting all the possible ones.
11
+
12
+ With that in mind, simply find the first 1-letter intersection between two word
13
+ to return "YES".
14
+ The worst case is to return "NO" after going through both words letter by letter.
Original file line number Diff line number Diff line change
1
+ # [ Two Strings] ( https://www.hackerrank.com/challenges/two-strings )
2
+
3
+ - Difficulty: ` #easy `
4
+ - Category: ` #ProblemSolvingBasic ` ` #dictionaries ` ` #hashmaps `
5
+
6
+ Given two strings, determine if they share a common substring.
7
+ A substring may be as small as one character.
8
+
9
+ ## Example
10
+
11
+ ` s1 = 'and' `
12
+ ` s1 = 'art' `
13
+
14
+ These share the common substring ` a ` .
15
+
16
+ ` s1 = 'be' `
17
+ ` s1 = 'cat' `
18
+
19
+ These do not share a substring.
20
+
21
+ ## Function Description
22
+
23
+ Complete the function twoStrings in the editor below.
24
+
25
+ twoStrings has the following parameter(s):
26
+
27
+ - ` string s1 ` : a string
28
+ - ` string s2 ` : another string
29
+
30
+ ## Returns
31
+
32
+ - ` string ` : either YES or NO
33
+
34
+ ## Input Format
35
+
36
+ The first line contains a single integer , the number of test cases.
37
+
38
+ The following pairs of lines are as follows:
39
+
40
+ The first line contains string ` s1 ` .
41
+ The second line contains string ` s2 ` .
42
+
43
+ ## Constraints
44
+
45
+ - ` s1 ` and ` s2 ` consist of characters in the range ascii[ a-z] .
46
+ - $ 1 \leq p \leq 10 $
47
+ - $ 1 \leq |s1|, |s2| \leq 10^5 $
48
+
49
+ ## Output Format
50
+
51
+ For each pair of strings, return ` YES ` or ` NO ` .
52
+
53
+ ## Sample Input
54
+
55
+ ``` text
56
+ 2
57
+ hello
58
+ world
59
+ hi
60
+ world
61
+ ```
62
+
63
+ ## Sample Output
64
+
65
+ ``` text
66
+ YES
67
+ NO
68
+ ```
69
+
70
+ ## Explanation
71
+
72
+ We have pairs to check:
73
+
74
+ 1 . ` s1 = "hello" ` , ` s2 = "world" ` . The substrings ` "o" ` and ` "l" `
75
+ are common to both strings.
76
+ 2 . ` a = "hi" ` , ` b = "world" ` . ` s1 ` and ` s2 ` share no common substrings.
77
+
78
+ ## Appendix
79
+
80
+ [ Solution notes] ( two-strings-solution-notes.md )
Original file line number Diff line number Diff line change 1
1
/**
2
- * @link Problem definition [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.md]]
2
+ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings.md]]
3
+ * @see Solution Notes [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two-strings-solution-notes.md]]
3
4
*/
4
5
5
6
package hackerrank
You can’t perform that action at this time.
0 commit comments