public String findCommmonAncestor(String[] commitHashes, String[][] parentHashes, String commitHash1, String commitHash2) {
    	
    	//store nodes that already visited
    	Set<String> set1 = new HashSet<String>();
    	Set<String> set2 = new HashSet<String>();
    	Queue<String> q = new LinkedList<String>();
    	q.offer(commitHash1);
    	set1.add(commitHash1);
    	
    	while(!q.isEmpty()) {
    		//find index in commitHashes
    		int index = findIndex(commitHashes, q.poll());
    		//find mapping parentHashes, then update set and enqueue
    		String[] parents = parentHashes[index];
    		if(parents==null) break;
    		for(String s : parents) {
    			if(s.equals(commitHash2)) return s;
    			if(!set1.contains(s)) {
    				q.offer(s);
        			set1.add(s);
    			}
    		}
    	}
    	
    	
    	q.offer(commitHash2);
    	set2.add(commitHash2);
    	while(!q.isEmpty()) {
    		int index = findIndex(commitHashes, q.poll());
    		String[] parents = parentHashes[index];
    		for(String s : parents) {
    			if(set1.contains(s)) return s;
    			if(!set2.contains(s)) {
    				q.offer(s);
    				set2.add(s);
    			}
    		}
    	}
    	return null;
    }