Expedia Coding Round Experience - Intern 2021 - GeeksforGeeks

24 Jun, 2021
Coding problems for Expedia Inten 2021: There were 2 coding questions and 6 MCQ’s for the coding round of the Expedia 2021 Intern Round.
Question 1: A number of ways to divide objects into groups, such that no group will have fewer objects than previously formed groups?
Example: 
objects=8, groups=4 Answer: 5
[1,1,1,5], [1,1,2,4], [1,1,3,3], [1,2,2,3], [2,2,2,2]
Input:
8 4 
Output:
5
Solution: 
Simple Approach: This problem can be solved by using recursion.
 
C++
// C++ program to count the// number of ways to divide objetcs in// groups. #include <bits/stdc++.h> using namespace std; // Function to count the number// of ways to divide the number objects// in groups.int count(int pos, int prev, int objects, int groups){     if (pos == groups) {        if (objects == 0)            return 1;        else            return 0;    }     // if objects is divides completely    // into less than groups    if (objects == 0)        return 0;     int solution = 0;     // put all possible values    // greater equal to prev    for (int i = prev; i <= objects; i++) {        solution += count(pos + 1, i, objects - i, groups);    }    return solution;} // Function to count the number of// ways to divide into objectsint WaysToGo(int objects, int groups){    return count(0, 1, objects, groups);} // Main Codeint main(){    int objects, groups;    objects = 8;    groups = 4;    cout << WaysToGo(objects, groups);    return 0;}
 
Time complexity: O(ObjectGroups)
Dynamic Approach: The above approach will fail as time complexity will exceed, so we will apply Dynamic Programming.
 
C++
// C++ implementation to count the// number of ways to divide objects in// groups. #include <bits/stdc++.h> using namespace std;// DP 3DArrayint dp[500][500][500]; // Function to count the number// of ways to divide the objects// in groups.int count(int pos, int prev, int objects, int groups){    // Base Case    if (pos == groups) {        if (left == 0)            return 1;        else            return 0;    }    // if objects is divides completely    // into groups    if (objects == 0)        return 0;     // If the subproblem has been    // solved, use the value    if (dp[pos][prev][objects] != -1)        return dp[pos][prev][objects];     int solution = 0;    // put all possible values    // greater equal to prev    for (int i = prev; i <= objects; i++) {        solution += count(pos + 1, i, objects - i, groups);    }     return dp[pos][prev][objects] = solution;} // Function to count the number of// ways to divide into groupsint WaystoDivide(int objects, int groups){    // Initialize DP Table as -1    memset(dp, -1, sizeof(dp));     return count(0, 1, objects, groups);} // Main Codeint main(){    int objects, groups;    objects = 8;    groups = 4;    cout << WaystoDivide(objects, groups);    return 0;}
Question 2: Minimum number of distinct elements after removing m items
Given an array of items, and i-th index element denotes the item id’s and given a number m, the task is to remove m elements such that there should be minimum distinct id’s left. Print the number of distinct IDs.
Examples:
Input : arr[] = { 2, 2, 1, 3, 3, 3}
           m = 3
Output : 1
Remove 1 and both 2's.So, only 3 will be
left that's why distinct id is 1.
Input : arr[] = { 2, 4, 1, 5, 3, 5, 1, 3}
           m = 2
Output : 3
Remove 2 and 4 completely. So, remaining ids
are 1, 3 and 5 i.e. 3
C++
#include <bits/stdc++.h>using namespace std; // Function to find distintc id'sint distIds(int a[], int n, int m){    unordered_map<int, int> mi;    vector<pair<int, int> > v;    int count = 0;     // Store the occurrence of ids    for (int i = 0; i < n; i++)        mi[a[i]]++;     // Store into the vector second as first and vice-versa    for (auto it = mi.begin(); it != mi.end(); it++)        v.push_back(make_pair(it->second, it->first));     // Sort the vector    sort(v.begin(), v.end());     int size = v.size();     // Start removing elements from the beginning    for (int i = 0; i < size; i++) {         // Remove if current value is less than        // or equal to m        if (v[i].first <= m) {            m -= v[i].first;            count++;        }         // Return the remaining size        else            return size - count;    }    return size - count;} // Main codeint main(){    int arr[] = { 2, 3, 1, 2, 3, 3 };    int n = sizeof(arr) / sizeof(arr[0]);     int m = 3;     cout << distIds(arr, n, m);    return 0;}
Time Complexity: O(n log n)
Expedia
Internship
Interview Experiences
Expedia
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Microsoft Interview Experience for Internship (Via Engage)
Persistent Systems Interview Experience (Martian Program)
Zoho Interview Experience (Off-Campus ) 2022
Zoho Corporation (Internship cum Offer Experience )
HashedIn by Deloitte Interview Experience for SDE Intern+FTE | (Off-Campus) 2022
Commonly Asked Java Programming Interview Questions | Set 2
Amazon Interview Questions
Amazon Interview Experience for SDE-1 (On-Campus)
Amazon Interview Experience
Microsoft Interview Experience for Internship (Via Engage)