Open In App

Moonfrog Labs Interview Experience | Set 3

Last Updated : 15 Nov, 2015
Improve
Improve
Like Article
Like
Save
Share
Report

Q1. Given a sequence of integers, find the longest increasing subsequence. Example:
arr = [1, 2, 5, 3, 7]
ans : [1, 2, 5, 7] or [1, 2, 3, 7]

arr = [4, 3, 1, 2]
ans: [1, 2].

Solution:




import java.util.Arrays;
  
/** @author hiccup  */
class LIS
{
    static int[] maxLIS;
    static int[] result;
  
    public static void getLCS(int[] arr)
    {
        if (null == arr || 0 == arr.length)
            return;
  
        maxLIS = new int[arr.length];
        /* At least LCS is 1 i.e. element is the
                   only one in given sequence */
        Arrays.fill(maxLIS, 1);
  
  
        /**
         *
         */
        for (int curIdx = 1; curIdx < arr.length; curIdx++)
        {
            for (int beginIdx = 0; beginIdx <= curIdx - 1; beginIdx++)
            {
                if (arr[curIdx] > arr[beginIdx])
                {
                    if (maxLIS[curIdx] < maxLIS[beginIdx] + 1)
                    {
                        //System.out.print(arr[curIdx] + "  ");
                        maxLIS[curIdx] = maxLIS[beginIdx] + 1;
                    }
                }
            }
        }
  
        int max = maxLIS[0];
        result = new int[arr.length];
        Arrays.fill(result, -1);
  
        int cpIdx = 0;
        for (int idx = 0; idx < maxLIS.length; idx++)
        {
            /* Put sequence at cpIdx   */
            if (-1 == result[maxLIS[idx] - 1])
            {
                result[cpIdx++] = arr[idx];
            }
        }
  
        /*  Print sequence       */
        for (int idx = 0; idx < result.length; idx++)
        {
            System.out.print(result[idx] + " ");
        }
    }
  
    public static void main(String[] args)
    {
        int[] arr = {1, 2, 5, 3, 7};
        LIS.getLCS(arr);
    }
}


[1, 2, 3, 3, 4]

—————————————————————————————————————————————–
Q2. Given a vectors of numbers of fixed length, for example:

v1 = [4, 3, 1, 2] v2 = [2, 4, 3, 5]

The relationship nested between two vectors is defined as follows:

if the corresponding entries of a vector are all smaller than the other vector, after rearranging entries of vector if needed, then first vector
is said to be nested in the other. Example

Not nested
v1 – [4, 3, 1, 2] v2 – [2, 4, 3, 5]
v2 – [2, 4, 3, 5] v1 – [4, 3, 1, 2]

After re-arranging:

Nested
v1 – [4, 3, 1, 2]
v2 – [5, 4, 2, 3]

Hence v1 is nested in v2.

Given a pair of such vectors , write a function as follows:

function isNested(Vec a, Vec b);

Result:
-1 if a is nested in b
1 if b is nested in a
0 if nesting is not possible.

———————————————————————————————————————-

Q3. Given a list of numbers in random order. Is it possible to pair all elements in the list in such a way that no two pairs share an element
and the sum of elements in a pair is divisible by 101. Example:

v1 [ 1, 100, 1]
Ans: No

v2 [1, 100, 100, 1] [2, 98, 101, 1]
Ans: Yes

v3 [1, 200, 100, 100, 2, 1]
Ans: yes



Previous Article
Next Article

Similar Reads

Moonfrog Labs Interview Experience | Set 4
1. Topological sort. 2. Reverse linked list in pairs. (1-&gt;2-&gt;3-&gt;4 to 2-&gt;1-&gt;4-&gt;3) 3. Print a binary tree in spiral order 4. Reverse an array without using subtract sign '-' anywhere in your code. 5. One DP problem in a 3*3 matrix which I don't remember exactly. 6. .org/minimum-number-of-jumps-to-reach-end-of-a-given-array/ Related
1 min read
Moonfrog Labs Interview Experience
Moonfrog Labs Interview Experience Recently I got interviewed at Moonfrog Labs. Here is my interview experience. Round 1(1 hour): The interviewer was very friendly and helping. She started with my introduction and discussed a bit about my current project. Q1. Check whether a graph can be converted to a tree or not. First we have to discuss the appr
2 min read
Moonfrog Labs Interview Questions
Round 1: 1&gt; given a number, and an encoding technique like 1-&gt; A, 2-&gt; B.... 26-&gt;Z, How may different valid encryption can be done. Like 123 can be decoded as ABC or LC or AW. so the count is 3 2&gt; given an array of -1, 0, 1 in an unsorted matter. sort it in order of n time complexity 3&gt; How to get the top 10 occurring words from a
1 min read
Moonfrog Labs Recruitment Process
This article will give you information about the company, its recruitment process, sample questions that have been asked previously, lots of experiences shared by other aspirants, and the portal where you can apply. [caption width="800"] [/caption] About Company: Moonfrog Labs was formed by skilled game developers that are dedicated to revolutioniz
2 min read
HP R & D Labs Interview Experience | Set 7 (For Experienced)
I would like to share my recent interview experience with HP R&amp;D Labs banglore. I have experience of 4 years into network protocol development. The opening position is for network protocol developer (Layer2/Layer3). Selected people were called for the drive. Totally, there are 5 rounds happened in a single day. (4 technical (1 written + 3 face
2 min read
SAP Labs Interview Experience | Set 32 (For Data Scientist)
Round 1: I didn't gave the test as it didn't open for my department. But during the interviews day they called for walk in interviews and went for that. I had only 1 round after which they said I 'll be having the second round but they might have got enough good students so that I had no 2nd round. Questions: Why Data Scientist Profile how would yo
1 min read
SAP Labs Interview Experience | Set 34 (On-Campus for Internship)
The interview process took 3 rounds : Round 1: Telephonic interview It took place for 40-60 minutes. Interviewer started with questions related to OOPs concept in java, example in real life etc. Then he asked questions like - How can we access private methods or private members of class outside the class? What if we declare our variables as static?
2 min read
Amadeus Labs Interview Experience | Set 4 (On Campus) | Full Time + Internship
Round 1: Amadeus Labs India, Bangalore recently visited Thapar Institute of Engineering and Technology to recruit for two different profiles, Software Developer and Quality Assurance. The first round was an online test that was conducted by SHL. The test was really very tough. It contained 2 sections - Numerical Reasoning and Verbal Reasoning. You
4 min read
Raja Software Labs Interview Experience | Set 2
Selection process 1) written test 2) Technical-round 1 3) Technical-round 2 Process begins after 10 minutes PPT. Written would be Pen and Paper based. 1) written - It contains 5 coding question you have to write only in C, C++, Java because they don't know Python (Director said I don't know Python if anyone write code in python will be rejected). L
2 min read
Walmart Labs Interview Experience | Set 16 (For Experienced)
Round 1: Online Round on Hacker Earth. Two questions were given - Given a string consisting only of A and B. Find the maximum length substring which is repeated exactly twice and is non overlapping. Given a positive Integer, find no of ways in which consecutive natural no.s can be added to get this no. Example - N = 15. Ans - 3 ( (1,2,3,4), (4,5,6)
2 min read