Facebook Interview Question for Software Developers


Team: Community Operations
Country: United States




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

l1=[1,3,4,12,24,45]
l2=[1,2,3,4,5,6,7,None,None,None,None,None,None]
def merge_into_l2(l1,l2):
    i=len(l1)-1
    j=len(l2)-len(l1)-1
    k=len(l2)-1
    while(i>=0 and j>=0 and k>=0):
        if(l1[i]>=l2[j]):
            l2[k]=l1[i]
            i-=1
            k-=1
        else:
            l2[k]=l2[j]
            j-=1
            k-=1
    return l2
print(merge_into_l2(l1,l2))
Thank You
-Nikhilkumar Kekan

- nikhil19kekan December 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Try this

l1=[1,2,3,4]
l2=[2,10,11,17,None,None,None,None]

- AF December 05, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I would do something like this,

public static void main(String[] args) {
    
    int[] a = {1, 2, 3, 4, 5};
    int[] b = {1, 1, 2, 2, 3, 3, 4, 4, 5};
    int[] c = new int[a.length + b.length];
    
    int i = 0, j = 0, end = 0;
    while (i < a.length && j < b.length)
        c[end++] = (a[i] <= b[j]) ? a[i++] : b[j++];
    while (i < a.length)
        c[end++] = a[i++];
    while (j < b.length)
        c[end++] = b[j++];
    
    System.out.println(Arrays.toString(c));
}

just so that I can avoid nulls & unnecessary if conditions
while takes just as much time even when split

- PeyarTheriyaa December 05, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

merge method from mergesort

- Anonymous December 06, 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