Facebook Interview Question for Software Engineers


Country: United States
Interview Type: In-Person




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

from collections import Counter
def count(arr):
    fs = [(tuple(Counter(x[::2]).items()), 
    	     (tuple(Counter(x[1::2]).items()))) 
    	     for x in arr]
    return sum(z for (x,z) in Counter(fs).items() if z>1)
    
print count(["abcd","cbad","bacd"])
print count(["abcd", "acbd", "adcb", "cdba",
"bcda", "badc"])

- adr August 09, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

calculate even, odd sum(ascii) and compute a hash for it. Answer will the number of different hashes generated.

- sriram.itech August 10, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class SpecialEquivalient {

    private int count = 0;

    SpecialEquivalient (String[] input) {
        Set<String> outputSet = new HashSet<String>();;
        for(String str : input) {
            String[] evenOdd = splitEvenOdd(str);
            String sortedString = sortString(evenOdd[0]) + sortString(evenOdd[1]);
            outputSet.add(sortedString);
        }
        count = outputSet.size();
    }

    String[] splitEvenOdd(String str) {
        char[] chars = str.toCharArray();
        String odd = new String();
        String  even = new String();
        for (int i=0; i<str.length(); i++) {
            if (i % 2 == 1) {
                odd += chars[i];
            } else {
                even += chars[i];
            }
        }
        return new String[] {odd, even};
    }

    String sortString(String str) {
        char[] charArray = str.toCharArray();
        Arrays.sort(charArray);
        return new String(charArray);
    }

    public int uniqueCount() {
        return count;
    }
}

- Sachin Magdum August 19, 2018 | 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