{"id":"bb453b41-5d67-442b-929b-082cf9ab8e36","name":"Sentence Similarity","description":"Given two sentences sentence1 and sentence2 each represented as a string array and given a 2d array of string pairs where each row contains two words {x,y} indicating that the word x and y are similar.\r\nReturn true if sentence1 and sentence2 are similar, or false if they are not similar. Two sentences are similar if they have the same length and sentence1[i] and sentences2[i] are similar.\r\n\r\nNote: Similarity relation is transitive.","inputFormat":"First line contains an integer denoting the sentence length.\r\nSecond line contaions the words of sentence1 separated by space.\r\nThird line contains the words of sentence2 separated by space.\r\nFourth line contains an integer m denoting number of pairs.\r\nEach of next m lines contains 2 words separated by space which are similar.","outputFormat":"Print true if Sentence1 and Sentence2 are similar else print false.","constraints":"1 &lt;= sentence1.length, Sentence2.length &lt;= 100000\r\n1 &lt;= sentence1[i].length, sentence2[i].length &lt;= 20\r\nsentence1[i] and sentence2[i] consist of lower-case and upper-case English letters.","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nunordered_map<string,string>parent;\nunordered_map<string,int>ranker;\n\nbool areSentencesSimilarTwo(vector<string>& sentence1, vector<string>& sentence2, vector<vector<string>>&pairs){\n \n}\n\nint main(){\n int n,m;\n cin>>n;\n \n vector<string> sentence1;\n vector<string>sentence2;\n for(int i=0;i<n;i++){\n string x;\n cin>>x;\n sentence1.push_back(x);\n }\n \n for(int i=0;i<n;i++){\n string x;\n cin>>x;\n sentence2.push_back(x);\n }\n cin>>m;\n vector<vector<string>>pairs(m,vector<string>(2));\n \n for(int i=0;i<m;i++){\n cin>>pairs[i][0];\n cin>>pairs[i][1];\n }\n \n \n if(areSentencesSimilarTwo(sentence1, sentence2, pairs))\n cout<<\"true\";\n else cout<<\"false\";\n}\n"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n\r\n String[] sentence1 = br.readLine().split(\" \");\r\n String[] sentence2 = br.readLine().split(\" \");\r\n\r\n int m = Integer.parseInt(br.readLine());\r\n\r\n String[][] pairs = new String[m][2];\r\n for (int i = 0; i < m; i++) {\r\n pairs[i] = br.readLine().split(\" \");\r\n }\r\n\r\n System.out.println(areSentencesSimilarTwo(sentence1, sentence2, pairs));\r\n\r\n }\r\n\r\n\r\n public static boolean areSentencesSimilarTwo(String[] Sentence1, String[] Sentence2, String[][] pairs) {\r\n\r\n }\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\ntreat fight miss\r\nlike train lost\r\n4\r\ntreat catch\r\ntrain fight\r\nlike catch\r\nmiss lost","sampleOutput":"true\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"7e07fddf-83bd-421e-848f-118f1f29541c","name":"Graphs For Intermediate","slug":"graphs-for-intermediate-493","type":0},{"id":"d8fc46c6-4e4d-444b-bafa-d4287175812a","name":"Sentence Similarity","slug":"sentence-similarity","type":1}],"next":{"id":"77149700-260b-4f01-a224-94a4de2e6caf","name":"Sentence Similarity MCQ","type":0,"slug":"sentence-similarity-mcq"},"prev":{"id":"63269729-629a-42cf-bd76-37a9cc270f59","name":"REDUNDANT CONNECTION 2","type":3,"slug":"redundant-connection-2"}}}

Sentence Similarity

Given two sentences sentence1 and sentence2 each represented as a string array and given a 2d array of string pairs where each row contains two words {x,y} indicating that the word x and y are similar. Return true if sentence1 and sentence2 are similar, or false if they are not similar. Two sentences are similar if they have the same length and sentence1[i] and sentences2[i] are similar. Note: Similarity relation is transitive.

{"id":"bb453b41-5d67-442b-929b-082cf9ab8e36","name":"Sentence Similarity","description":"Given two sentences sentence1 and sentence2 each represented as a string array and given a 2d array of string pairs where each row contains two words {x,y} indicating that the word x and y are similar.\r\nReturn true if sentence1 and sentence2 are similar, or false if they are not similar. Two sentences are similar if they have the same length and sentence1[i] and sentences2[i] are similar.\r\n\r\nNote: Similarity relation is transitive.","inputFormat":"First line contains an integer denoting the sentence length.\r\nSecond line contaions the words of sentence1 separated by space.\r\nThird line contains the words of sentence2 separated by space.\r\nFourth line contains an integer m denoting number of pairs.\r\nEach of next m lines contains 2 words separated by space which are similar.","outputFormat":"Print true if Sentence1 and Sentence2 are similar else print false.","constraints":"1 &lt;= sentence1.length, Sentence2.length &lt;= 100000\r\n1 &lt;= sentence1[i].length, sentence2[i].length &lt;= 20\r\nsentence1[i] and sentence2[i] consist of lower-case and upper-case English letters.","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nunordered_map<string,string>parent;\nunordered_map<string,int>ranker;\n\nbool areSentencesSimilarTwo(vector<string>& sentence1, vector<string>& sentence2, vector<vector<string>>&pairs){\n \n}\n\nint main(){\n int n,m;\n cin>>n;\n \n vector<string> sentence1;\n vector<string>sentence2;\n for(int i=0;i<n;i++){\n string x;\n cin>>x;\n sentence1.push_back(x);\n }\n \n for(int i=0;i<n;i++){\n string x;\n cin>>x;\n sentence2.push_back(x);\n }\n cin>>m;\n vector<vector<string>>pairs(m,vector<string>(2));\n \n for(int i=0;i<m;i++){\n cin>>pairs[i][0];\n cin>>pairs[i][1];\n }\n \n \n if(areSentencesSimilarTwo(sentence1, sentence2, pairs))\n cout<<\"true\";\n else cout<<\"false\";\n}\n"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n\r\n String[] sentence1 = br.readLine().split(\" \");\r\n String[] sentence2 = br.readLine().split(\" \");\r\n\r\n int m = Integer.parseInt(br.readLine());\r\n\r\n String[][] pairs = new String[m][2];\r\n for (int i = 0; i < m; i++) {\r\n pairs[i] = br.readLine().split(\" \");\r\n }\r\n\r\n System.out.println(areSentencesSimilarTwo(sentence1, sentence2, pairs));\r\n\r\n }\r\n\r\n\r\n public static boolean areSentencesSimilarTwo(String[] Sentence1, String[] Sentence2, String[][] pairs) {\r\n\r\n }\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\ntreat fight miss\r\nlike train lost\r\n4\r\ntreat catch\r\ntrain fight\r\nlike catch\r\nmiss lost","sampleOutput":"true\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"7e07fddf-83bd-421e-848f-118f1f29541c","name":"Graphs For Intermediate","slug":"graphs-for-intermediate-493","type":0},{"id":"d8fc46c6-4e4d-444b-bafa-d4287175812a","name":"Sentence Similarity","slug":"sentence-similarity","type":1}],"next":{"id":"77149700-260b-4f01-a224-94a4de2e6caf","name":"Sentence Similarity MCQ","type":0,"slug":"sentence-similarity-mcq"},"prev":{"id":"63269729-629a-42cf-bd76-37a9cc270f59","name":"REDUNDANT CONNECTION 2","type":3,"slug":"redundant-connection-2"}}}
plane

Editor


Loading...

Sentence Similarity

easy

Given two sentences sentence1 and sentence2 each represented as a string array and given a 2d array of string pairs where each row contains two words {x,y} indicating that the word x and y are similar. Return true if sentence1 and sentence2 are similar, or false if they are not similar. Two sentences are similar if they have the same length and sentence1[i] and sentences2[i] are similar. Note: Similarity relation is transitive.

Constraints

1 <= sentence1.length, Sentence2.length <= 100000 1 <= sentence1[i].length, sentence2[i].length <= 20 sentence1[i] and sentence2[i] consist of lower-case and upper-case English letters.

Format

Input

First line contains an integer denoting the sentence length. Second line contaions the words of sentence1 separated by space. Third line contains the words of sentence2 separated by space. Fourth line contains an integer m denoting number of pairs. Each of next m lines contains 2 words separated by space which are similar.

Output

Print true if Sentence1 and Sentence2 are similar else print false.

Example

Sample Input

3 treat fight miss like train lost 4 treat catch train fight like catch miss lost

Sample Output

true

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode