
Asked in LimeRoad
Word Ladder Problem Statement
Given two strings, BEGIN
and END
, along with an array of strings DICT
, determine the length of the shortest transformation sequence from BEGIN
to END
. Each transformation involves changing exactly one alphabet, and the resulting word after each transformation must be present in DICT
.
Input:
Integer T representing number of test cases.
For each test case:
A string BEGIN.
A string END.
An integer N representing the length of the DICT array.
N space-separated strings denoting words in DICT.
Output:
For each test case, the output is a single integer indicating the length of the shortest transformation sequence from BEGIN to END. Output each test case result on a separate line.
Example:
# Example 1 Input:
2
hit
cog
5
hot dot dog lot log
hit
hot
2
hot cog
Output:
# Example 1 Output:
5
2
Constraints:
- 1 ≤ T ≤ 5
- 1 ≤ N ≤ 102
- 1 ≤ |S| ≤ 102
- All words have the same length.
- All transformations involve only lowercase English letters.
BEGIN
will not equalEND
.
Note:
Return -1
if no transformation sequence from BEGIN
to END
is possible. Implement the function, as printing is handled separately.

AnswerBot
4mo
The Word Ladder problem involves finding the shortest transformation sequence from one word to another by changing one letter at a time.
Use breadth-first search to find the shortest transformation seq...read more
Help your peers!
Add answer anonymously...
Top Full Stack Developer Interview Questions Asked at LimeRoad
Q. Valid Parentheses Problem Statement Given a string 'STR' consisting solely of th...read more
Q. Problem: Ninja's Robot The Ninja has a robot which navigates an infinite number ...read more
Q. Group Anagrams Problem Statement Given an array or list of strings called inputS...read more
Interview Questions Asked to Full Stack Developer at Other Companies
Top Skill-Based Questions for LimeRoad Full Stack Developer
Web Development Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
JavaScript Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

