MobiCastle Interview Question for Software Engineers


Country: Switzerland
Interview Type: Phone Interview




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

Looking for coaching on interview preparation?
Visit AONECODE.COM for ONE-TO-ONE private lessons by FB, Google and Uber engineers!

System Design (for candidates of FB, LinkedIn, AMZ, Google and Uber etc)
Algorithms (DP, Greedy, Graph etc. advanced algorithms and clean coding)
Interview questions sorted by companies
Mock Interviews

Ace G, U, FB, Amazon, LinkedIn, MS and other top-tier interviews in weeks of training.

Feel free to email us aonecoding@gmail.com with any questions. Thanks!

//Extra space O(1) Runtime O(nlogn)
    List<Integer> getFibonacciNumber(int[] nums) {
        List<Integer> fibonacciNumbers = new ArrayList<>();
        Arrays.sort(nums);
        int fib1 = 1, fib2 = 1;
        for(int i = 0; i < nums.length;) {
            if(nums[i] < fib2) {
                i++;
            } else if(nums[i] == fib2) {
                fibonacciNumbers.add(nums[i]);
                i++;
            } else {
                int fib3 = fib1 + fib2;
                fib1 = fib2;
                fib2 = fib3;
            }
        }
        return fibonacciNumbers;
    }


    //Math Solution: Extra space O(1) Runtime O(n)
    List<Integer> getFibonacciNumbers(int[] nums) {
        List<Integer> fibonacciNumbers = new ArrayList<>();
        for(int n: nums) {
            if(isFibonacci(n)) fibonacciNumbers.add(n);
        }
        return fibonacciNumbers;
    }
    boolean isFibonacci(int n)
    {
        // n is Fibonacci if one of 5*n*n + 4 or 5*n*n - 4 or both
        // is a perfect square
        return isPerfectSquare(5*n*n + 4) ||
                isPerfectSquare(5*n*n - 4);
    }

    boolean isPerfectSquare(int x)
    {
        int s = (int) Math.sqrt(x);
        return (s*s == x);
    }

- aonecoding February 15, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Iterate through the list and check if 5(Num)2 +4 OR 5(Num)2 - 4 is a prefect square .
5*n*n + 4 or 5*n*n - 4
add to list if true .

- Saurabh February 13, 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