Google Interview Question for Data Engineers


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

p = 'abc'
q = 'cba'

'case 1: if a never repeats eg: abca so a can come after c but before b. so then i have to sort it'
sort_letter = {}


def find_precedence(str):
    for i in range(len(str)):
        sort_letter[str[i]] = str[i+1:]
    print(sort_letter)

def check_order(q,sort_letter):
    correct =  0
    for i in range(len(q)):
        if q[i] in sort_letter:
            print("checking - ",q[i]," ",sort_letter[q[i]]," ", q[i+1:])
            if sort_letter[q[i]] in q[i+1:] or  q[i+1:] in sort_letter[q[i]] :
                correct =1
            if q[i+1:] =='' and sort_letter[q[i]]:
                correct = 0
    print(correct)


find_precedence(p)
check_order(q,sort_letter)

- Anonymous January 20, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can a queue with hashmap of counts (to check if there's precendence constraint) work in this case? What do you think?

- Anonymous January 20, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

const isOrdered = (order, str) => {
	const orderRank = order.split("");
	let lastSeen = -1;

	return str.split("").reduce((accum, val) => {
		if (!accum) {
			return accum;
		}
		const lookUp = orderRank.indexOf(val),
			isOrdered = (lastSeen <= lookUp) || lookUp === -1;
		lastSeen = lookUp;
		return isOrdered;	
	});
};

- Sasuke January 20, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Have a HashSet that stores the priority (ordering) of the string "abc"
Loop through characters of the given string, for each character check the priority
If the priority is not present OR if priority is same, go to the next character
Else If the priority is greater, increase the current_seen priority and go to the next character
Else return false

If reached end of string, return true

- Sneha July 29, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Check

- Boo July 29, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Time complexity: O(n + m)
Space complexity: O(1), assuming both strings are ASCII

public static boolean checkOrder(String pattern, String str) {
    int[] label = new int[128];
    int order = 1;
    for (char c : pattern.toCharArray()) {
        label[c] = order;
        order++;
    }

    int lastOrder = -1;
    for (char c : str.toCharArray()) {
        int currOrder = label[c];
        if (currOrder == 0) continue;
        if (lastOrder != -1 && currOrder < lastOrder) return false;
        lastOrder = currOrder;
    }
    return true;
}

- Tinker January 06, 2019 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More