Pure Storage | OA 2019 | Lock Aquire/Release Events, MCQ, Number Score

MCQs:

  • image
  • image
  • Given a binary tree of routers, if one node fails - all its descendents become unreachable. 3 MCQs about: you choose a random node what is the probability of being able to reach that node, what nodes are most likely to fail etc.

Coding Question 1:
The question was about checking if the given sequence of events is valid. The conditions are:
The order of release should be reverse of aquiring(stack)
A locked lock can not be aquired again
A lock has to be locked before releasing
There should be no dangling locks

My Code
	    // Complete the check_log_history function below.
    static int check_log_history(List<String> events) {
        HashSet<Integer> hs = new HashSet();
        Stack<Integer> st = new Stack();
        for(int i = 0; i < events.size(); i++){
            String e = events.get(i);
            String name = e.split(" ")[0];
            int num = Integer.parseInt(e.split(" ")[1]);
            if(name.equals("ACQUIRE")){
                if(hs.contains(num)){
                    return i+1;
                } 
                st.push(num);
                hs.add(num);
            }else{
                if(!hs.contains(num) || st.peek() != num){
                    return i+1;
                }
                st.pop();
                hs.remove(num);
            }     
        }
        return st.empty() ? 0 : events.size()+1;

    }

Coding Question 2:

Number Score:
V1: https://leetcode.com/discuss/interview-question/390058/pure-storage-oa-2019-number-score
V2: https://leetcode.com/discuss/interview-question/406130/Pure-Storage-or-OA-2019-or-Number-Score-V2

Comments (16)