The Leetcode file system keeps a log each time some user performs a change folder operation.

The operations are described below:


	"../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).
	"./" : Remain in the same folder.
	"x/" : Move to the child folder named x (This folder is guaranteed to always exist).


You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step.

The file system starts in the main folder, then the operations in logs are performed.

Return the minimum number of operations needed to go back to the main folder after the change folder operations.

&nbsp;
Example 1:



Input: logs = ["d1/","d2/","../","d21/","./"]
Output: 2
Explanation: Use this change folder operation "../" 2 times and go back to the main folder.


Example 2:



Input: logs = ["d1/","d2/","./","d3/","../","d31/"]
Output: 3


Example 3:

Input: logs = ["d1/","../","../","../"]
Output: 0


&nbsp;
Constraints:


	1 &lt;= logs.length &lt;= 103
	2 &lt;= logs[i].length &lt;= 10
	logs[i] contains lowercase English letters, digits, '.', and '/'.
	logs[i] follows the format described in the statement.
	Folder names consist of lowercase English letters and digits.


class Solution:
    def minOperations(self, logs: List[str]) -> int:
        m='../'
        r='./'
		#create an empty stack
        stk=[]
		#iterate through the list
        for i in logs:
			#if Move to the parent folder (../) operator occurs and stack is not empty, pop element from stack
            if(i==m):
                if(len(stk)>0):
                    stk.pop()
			#else if Remain in the same folder (./) operator occurs, do nothing and move to next element in list
            elif(i==r):
                continue
			#else add element to the stack
            else:
                stk.append(i)
		#now return the size of the stack which would be the minimum number of operations needed to go back to the main folder
        return(len(stk))
		```
class Solution {
    public int minOperations(String[] logs) {
         var stack = new Stack<String>();
        for(var log : logs){
            if(log.equals("../")){
                if(!stack.empty())
                    stack.pop();
            }else if(log.equals("./")){

            }else{
                stack.push(log);
            }
        }
        return stack.size();
    }
}
//1.using stack
class Solution {
public:
    int minOperations(vector<string>& logs) {
	
        if(logs.size()==0) return 0;
		
        stack<string> st;
        for(auto x: logs){
            if (x[0] != '.')  //Move to the child folder so add children
                st.push(x);
            else if(x=="../"){ // Move to the parent folder of the current folder so pop
                 if(!st.empty())  st.pop(); 
                 else continue; //don’t move the pointer beyond the main folder.
            }
        }
        return st.size();
    }
};
//2.
class Solution {
public:
    int minOperations(vector<string>& logs) {
         int ans = 0;
        for (string log : logs) {
            if (log == "../") { // go deeper
                ans--; 
                ans = max(ans, 0);
            } else if (log != "./") // one level up
			   ans++; 
        }
        return ans;
    }
};
//3.
class Solution {
public:
    int minOperations(vector<string>& logs) {
        int res = 0;
        for (string s : logs) {
            if (s=="../") res = max(0, --res);
            else if (s=="./") continue;
            else res++;
        }
        return res;
    }
};
var minOperations = function(logs) {
    let count = 0;
    for(i=0;i<logs.length;i++){
        if(logs[i] === '../') {
            if(count > 0)  count = count - 1;
            continue
        }
        if(logs[i] === './') continue;
        else count = count + 1;
    }
    return count
};
Crawler Log Folder