# This problem is not well-defined. It should state that 4-space is considered as a TAB under certain situation.

• After many try-and-error, I finally figured out the solution is required to handle the blank spaces in a special way. I think it should be stated in the problem statement, not just let people guess this from the expected answers. This will waste many people a lot of time....

• the solution is required to handle the blank spaces in a special way.

That's not true. It's the opposite. You should not handle them in any special way.

• This post is deleted!

• @StefanPochmann there is one test case to expect "dir\n file.txt" can be handled, and another case is "dir\n file.txt". either bad test cases, or bad problem description.

• @StefanPochmann @yubad2000 may be correct here. Look at this test case
`"dir\n file.txt"`
There are 8 spaces before file.txt and this does not mean 2 tabs. It means 1 tab and filename `" file.txt"`. I am sure of this because the answer for this test case is 16 which is
`"dir/ file.txt"`.
So the point is, we cannot simply convert noOfspaces/4 to number of tabs.

• @mragank2 Nah, you people really just need to get that idea out of your head that spaces are anything special. Just treat them like any other normal character (e.g., like 'x').

• @mragank2
@StefanPochmann is right. I think you are confused with this: Just "\n" means root separator. So ”dir\n(4-space) file.txt" mean there is a file named "(4-space)file.txt" at root directory, whose length is 12. Accordingly, "dir\n(4-space)(4-space)file.txt means there is a file names "(4-space)(4-space)file.txt" at root directory, whose length is 16. A file name starting with space is allowed.
@StefanPochmann explain it at https://discuss.leetcode.com/topic/55651/4-space-considered-as-a-tab-is-totally-confusing-which-makes-the-string-ambiguous-and-test-case-wrong .

• my straight forward idea is the same with @yubad2000 while after reading the answer of @StefanPochmann and @renwoxing I agree the question is not problem but it does not clear tell us '\n' means root while '\t' means entering subfolder. It would be nicer if the question is more clear. There is no mapping between 4-space and TAB.

``````// dir\n(4-space) file.txt
root--"dir"
|--"    file.txt"
//longest is "    file.txt"

// dir\n\t(4-space) file.txt
root--"dir"
|--"    file.txt"
//longest is "dir/    file.text"``````

• I agree with you. I hit the same situation. My code is the following

'''
class Solution {
public:
void parse(string str, stack<int>& flen, int& maxlen) {
size_t pos = str.find("\n");
if(pos == string::npos || pos+1==string::npos) {
if(str.find(".")==string::npos) maxlen = 0;
else maxlen = flen.empty()?max(maxlen, (int)str.length()):max(maxlen, flen.top()+(int)str.length());
return;
}
if(flen.empty()) flen.push((int)pos+1);
else flen.push(flen.top()+(int)pos+1);
int nt = 0;
size_t tpos = str.find("\t",pos+1);
while(tpos == pos+1) {
nt++;
pos = tpos;
tpos = str.find("\t",pos+1);
}
if(flen.size()>nt) maxlen = max(maxlen, flen.top());
while(flen.size()>nt) flen.pop();
if(str.substr((int)pos+1,1)==" ") parse(str.substr((int)pos+2), flen, maxlen);
else parse(str.substr((int)pos+1), flen, maxlen);
return;
}
int lengthLongestPath(string input) {
stack<int> flen;
int maxlen = 0;
parse(input, flen, maxlen);
return maxlen;
}
};
'''

• This post is deleted!

• @wang4 Please actually read my post that you replied to.

• @StefanPochmann My apology. You are right. It is AC.

• it does not clear tell us '\n' means root while '\t' means entering subfolder

Yeah, might be better to state something like that explicitly. On the other hand, I think the examples makes that pretty clear. And the examples don't contain even a single space character. So one must wonder why people add extra code to special-treat space characters when they have absolutely no reason to do so.

• This post is deleted!

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.