0% found this document useful (0 votes)
79 views5 pages

Sunday Evening Code

The document discusses three questions related to word transformations, word frequency counting, and sorting reviews by "goodness" value. Question 1 asks to find all shortest word transformation sequences between a start and end word using a dictionary, where each step differs by one letter. Question 2 asks to count the frequency of each word in a text and output them sorted by frequency. Question 3 asks to sort hotel reviews in descending order based on the number of "good words" contained in each review, breaking ties by original order.

Uploaded by

Gayatri aptil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views5 pages

Sunday Evening Code

The document discusses three questions related to word transformations, word frequency counting, and sorting reviews by "goodness" value. Question 1 asks to find all shortest word transformation sequences between a start and end word using a dictionary, where each step differs by one letter. Question 2 asks to count the frequency of each word in a text and output them sorted by frequency. Question 3 asks to sort hotel reviews in descending order based on the number of "good words" contained in each review, breaking ties by original order.

Uploaded by

Gayatri aptil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Question 1: A transformation sequence from word

beginWord to word endWord using a dictionary wordList is a


sequence of words beginWord -> s1 -> s2 -> ... -> sk such
that:
● Every adjacent pair of words differs by a single letter.
● Every si for 1 <= i <= k is in wordList. Note that
beginWord does not need to be in wordList.
● sk == endWord
Given two words, beginWord and endWord, and a dictionary
wordList, return all the shortest transformation sequences
from beginWord to endWord, or an empty list if no such
sequence exists. Each sequence should be returned as a list of
the words [beginWord, s1, s2, ..., sk].

Example 1:
Input: beginWord = "hit", endWord = "cog", wordList =
["hot","dot","dog","lot","log","cog"]
Output:
[["hit","hot","dot","dog","cog"],["hit","hot","lot","log
","cog"]]
Explanation: There are 2 shortest transformation
sequences:
"hit" -> "hot" -> "dot" -> "dog" -> "cog"
"hit" -> "hot" -> "lot" -> "log" -> "cog"

Example 2:
Input: beginWord = "hit", endWord = "cog", wordList =
["hot","dot","dog","lot","log"]
Output: []
Explanation: The endWord "cog" is not in wordList,
therefore there is no valid transformation sequence.

Constraints:
● 1 <= beginWord.length <= 5
● endWord.length == beginWord.length
● 1 <= wordList.length <= 1000
● wordList[i].length == beginWord.length
● beginWord, endWord, and wordList[i] consist of
lowercase English letters.
● beginWord != endWord
● All the words in wordList are unique.

Question 2: In the given file named input, find the frequency


of all the words and print as per the following format.
The first column of each line of the output should be the
frequency of the word followed by all the words of that
frequency arranged in lexicographical order separated with
space “ ”
Sort the words in the ascending order of frequency.
For simplicity, assume that
● Words are case sensitive, i.e. The and the are treated as
different words.

Example:
Assume that input has following content:
the day is sunny
it is the sunny day
we can go out

Your script should output the following, sorted by the


ascending frequency:
1 can go it out we
2 day is sunny the

Question 3: Given a set of reviews provided by the customers


for different hotels and a string containing Good Words, you
need to sort the reviews in descending order according to their
Goodness Value (Higher goodness value first). We define the
Goodness Value of a string as the number of Good Words in
that string.

NOTE: Sorting should be stable. If review i and review j have


the same Goodness Value then their original order would be
preserved.

You are expected to use Trie in an Interview for such


problems

Problem Constraints
1 <= No.of reviews <= 200
1 <= No. of words in a review <= 1000
1 <= Length of an individual review <= 10,000
1 <= Number of Good Words <= 10,000
1 <= Length of an individual Good Word <= 4
All the alphabets are lower case (a - z)

Input Format
First argument is a string A containing "Good Words"
separated by "_" character

Second argument is a vector B of strings containing Hotel


Reviews. Review strings are also separated by "_" characters.
Output Format
Return a vector of integers which contain the original
indexes of the reviews in the sorted order of reviews.

Example Input
Input 1:

A = "cool_ice_wifi"
B = ["water_is_cool", "cold_ice_drink",
"cool_wifi_speed"]

Example Output
Output 1:

[2, 0, 1]

Example Explanation
Explanation 1:

sorted reviews are ["cool_wifi_speed", "water_is_cool",


"cold_ice_drink"]

You might also like