Open In App

TurboHire Internship Interview Experience

Last Updated : 06 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Round 1(1 hour 30 minutes): Consisted of 3 Coding Questions.

Coding Questions were:

  1. SHIPMENTS 1

    There are N ships standing at the port of Byteland. Bob is the supervisor of the port. Its his job to load the ship with some cargo. Without wasting any time, he loaded wash ship with some random weight of cargo. However, captains of all the ships have decided that they will not take the cargo unless the weight of cargo in each ship is the same. Now to fix this and that too in the least possible number of moves else he will be in trouble. One move means moving a ton of cargo from one ship to another. He needs your help in finding minimum number of moves.

    Input: The first line consists of an integer N (1<=N<=10^4) i.e., number of ships and the next line consists of current weight of cargo in each ship (1<=W<=10^4).

    Output: Print the minimum number of moves, if it’s impossible to have equal weight on each ship, then print -1.

    Sample Input 1

    5

    1 1 1 1 6

    Sample Output 1

    4

    Sample Input 2

    10

    4 3 2 5 2 1 2 3 3 4

    Sample Output 2

    -1

    And the code I submitted was,

    C++




    #include <bits/stdc++.h>
    using namespace std;
    int main ()
    {
        int n;
        cin >> n;
        int a[n];
        int s=0;
        for(int i=0;i<n;i++)
        {
            cin >> a[i];
            s=s+a[i];
        }
        if(s%n!=0)
        cout << -1 <<"\n";
        else
        {
            int k=s/n;
            int s1=0;
            int ans=0;
            for(int i=0;i<n;i++)
            {
                if(a[i]>k)
                {
                    s1=s1+(a[i]-k);
                }
                else
                {
                    ans=ans+abs(a[i]-k);
                    s1=s1-abs(a[i]-k);
                }
            cout << ans <<"\n";
        
    }

    
    

    The above solution passed all sample and hidden test cases.

  2. Star Ascension

    Analyze the output given in the samples for an input N. Write a program that prints the similar pattern.

    Input: One line containing an integer, N

    Output: A star ‘*’  and a Numerical pattern, to be deduced from the samples.

    Constraints : 0<N<999

    Sample Input 1

    1

    Sample Output 1

    *

    Sample Input 2

    2

    Sample Output 2

    1*

    *2

    Sample Input 3

    3

    Sample Output 3

    12*

    1*3

    *23

    C++




    #include <iostream>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        int arr[n][n];
        for (int i = 0; i < n; i++) {
      
            for (int j = 0; j < n; j++) {
                arr[i][j] = j + 1;
            }
        }
      
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
      
                if ((i + j) == (n - 1))
                    cout << '*';
                else
                    cout << arr[i][j];
            }
            cout << "\n";
        }
        return 0;
    }

    
    

    The above solution passed all sample and hidden test cases.

  3. Boys and Girls

    You have x no of boys and y no of girls. You have to align them in a straight line such that minimum number of boys and minimum number of girls stand together. Output the max of the min of above two.

    Input: Two integer x, y i.e., no of boys and girls.

    Output: Max of min of boys and girls standing together.

    Sample Input : 

    3 4

    Sample Output :

    1

    C++




    #include <algorithm>
    #include <cmath>
    #include <iostream>
    using namespace std;
    int main()
    {
        int x, y, minm, maxm, res;
        cin >> x >> y;
        minm = std::min(x, y);
        maxm = std::max(x, y);
        res = ceil((maxm * 1.0) / (minm + 1));
        cout << res;
        return 0;
    }

    
    

    The above solution passed all sample and hidden test cases.

Round 2(30 minutes): This round was simply the discussion of Round 1 and also a few more coding questions, I only had to tell the logic and approach.

Questions were:

  1. x no of cars are present and their speeds are given in an array. You have to calculate how many times does a car overcomes the other. Example [5,4,3] is the speed array, car with speed 5 overcomes the other two, so the answer is 2.
  2. You are given 2 Linked List, you’ve to return the node value of intersection of two Linked List.

I was able to tell the approach of 1st question but failed to answer 2nd.

Final Verdict: SELECTED



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads