If I have a string like ......
Microsoft Interview Questions and Answers
(Continued from previous question...)
103. If I have a string like ......
Question:
If I have a string like
www.bing.com/abc/asd/asdffg/../asdasd/.../asda/../.../
this is a example ,
if you have /../ then dont remove the letters and / before , just remove /../
www.bing.com/abc/asd/asdffg/asdasd/.../asda/.../
Another example
if you have /.../ then remove the letters before and itself
www.bing.com/abc/asd/asdffg/../../
maybe an answer:
This can be done easily by a perl using split
print "Enter the string \n";
$a = <>;
@b = split(/\.\.+\//,$a);
print "The modified string is \n";
print @b;
Split it with '/' Use a stack and push elements in the stack, whenever you encounter a ..., pop the last element out of the stack. Whenever u get .. then ignore it
then pop everything and prepend it
(Continued on next question...)
Other Interview Questions
|