public String simplifyPath(String path) {
        // Note: The Solution object is instantiated only once and is reused by each test case.
    	Stack<String> stack = new Stack<String>();
    	String elements[] = path.split("/");
    	for (int i = 0; i < elements.length; i++)
    	{
    		if (!elements[i].isEmpty() && !elements[i].equals("."))
    		{
    			if (elements[i].equals(".."))
    			{
    				if(!stack.isEmpty())
    					stack.pop();
    			}
    			else
    				stack.push(elements[i]);
    		}
    	}
    	
    	if (stack.isEmpty())
    		return "/";
    	
    	String ret = "";
    	while(!stack.isEmpty())
    	{
    		ret = "/" + stack.pop() + ret;
    	}
    	return ret;
    }