Grokking Meta Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
for alien dictionary, I believe they added extra test cases that makes this solu...

John Smith

Mar 7, 2022

for alien dictionary, I believe they added extra test cases that makes this solution fail. I copy-pasted it over too

4

0

Comments
Comments
Design Gurus
Design Gurus4 years ago

Can you please elaborate? Who added extra test case? Can you paste test cases here.

A
Alex Pitman4 years ago

I believe he's talking about this test case on Leetcode: ["abc","ab"], this fails using the provided implementation. Since the ordering is invalid ("ab" should come before "abc"), they expect an empty string as the result instead of returning "abc" as the correct orderi...

A
Alex Pitman4 years ago

Adding the following snippet to the inner for loop handles this test case:

// Handle cases like ["abc", "ab"] if (j == length - 1 && w1.length() > w2.length()) { return ""; }

Design Gurus
Design Gurus4 years ago

This is not a valid input. From the problem statement:

It is given that the input is a valid dictionary and there exists an ordering among its alphabets.

L
Learner 3 years ago

I understand it is not a valid input,. Just to be on the safer side, for the sake of interviews, we can use the following to check for such a testcase: string w1 = words[i], w2 = words[i + 1]; for (int j = 0; j < max(w1.length(), w2.length()); j++) { if(j== w1 .length()...

T N
T Na year ago

I struggled with the same issue with the new, invalid test cases. Here's the Python code

# populate the graph and inDegree for i in range(0, len(words) - 1): w1, w2 = words[i], words[i+1] for j in range(0, max(len...

On this page