ROLE: Software Developer
Recruitment Process
ROUND– I: Online Assessment
ROUND – II: Online Assessment (Coding Round)
Some of the important topics/questions asked in the drive:
ROUND- I- Online Assessment
What will be the output of the following C++ code.
#include<iostream> using namespace std;
class Base{
public:
virtual void show() = 0;
};
int main(){
Base b;
Base "bp;
}
2. What will be the output of this code?
#include <iostream>
#include <map>
using namespace std;
int main() {
map<int, string> m = {{1, "a"}, {2, "b"}};
auto print = [] (auto pair) {
cout << pair.first << "-" << pair.second << " ";
};
for (auto& p: m) print(p);
return 0;}
3. What will be the output of this code?
#include <unordered_map>
#include <iostream>
using namespace std;
int main() {
unordered_map<string, int> um = {{"a", 1}, {"b", 2}};
cout << um["c"] << endl;
}
4. What feature does structured binding provide in C++?
     •   Automatic memory management
     •   Decomposition of objects into individual named variables
     •   Compile-time evaluation
     •   Type inference for class
5. Which of the following STL algorithms can be used to check if all elements in a
container satisfy a condition?
     •   std::all_of
     •   std::find
     •   std::accumulate
     •   std::sort
6. How many vtables are likely to be associated with class C, and how many vptrs will
the object objC likely contain?
class A {
public:
virtual void methodA() { std::cout << "A::methodA" << std::endl; }
};
class B {
public:
virtual void methodB() { std::cout << "B:: methodB" << std::endl; }
};
class C: public A, public B {
public:
void methodA() override { std::cout << "C:: methodA" << std::endl; }
void methodB() override { std::cout << "C:: methodB" << std::endl; }
virtual void methodC() { std::cout << "C:: methodC" << std::endl; }
7. Which of the following statements about object slicing is TRUE?
     •   Object   slicing   only occurs when pointers are used
     •   Object   slicing   can be avoided by using references or pointers to base class
     •   Object   slicing   allows access to derived class members through base class objects
     •   Object   slicing   is not possible in C++
8. Which data structure is mostly used to convert the recursive implementation of an
algorithm to a non-recursive one?
     •   Stack
     •   Queue
  •   Array
  •   Tree
  •   Map
9. Which statement about constexpr is correct?
  •   constexpr   functions can only contain a single return statement.
  •   constexpr   variables must be initialized with a compile-time constant expression.
  •   constexpr   can only be used with integral types.
  •   constexpr   functions cannot have loops or branches.
10. Which smart pointer would you use to ensure exclusive ownership of a
dynamically allocated object?
  •   std::unique_ptr
  •   std::shared_ptr
  •   std::weak_ptr
  •   std::auto_ptr
CODING
  1. What will be the output of the following code?
     #include <iostream>
     #include <set>
     using namespace std;
      int main() {
         set<int> s = {5, 1, 3, 5, 2};
         s.insert(4);
         s.erase(1);
         for (int x : s)
            cout << x << " ";
         return 0;
      }
  2. What will be the output of the following code?
     #include <iostream>
     using namespace std;
      class Base {
      public:
         virtual void f() { cout << "Base::f "; }
         void g()      { cout << "Base::g "; }
      };
      class Derived : public Base {
      public:
         void f() override { cout << "Derived::f "; }
         void g()        { cout << "Derived::g "; }
      };
      int main() {
         Base* b = new Derived();
       b->f();
       b->g();
       return 0;
   }
3. Write the output for the following program.
   #include <iostream>
   using namespace std;
   class Base {
   public:
      virtual void show() { cout << "Base "; }
   };
   class Derived : public Base {
   public:
      void show() override { cout << "Derived "; }
   };
   void print(Base b) {
      b.show();
   }
   int main() {
      Derived d;
      print(d);
      return 0;
   }
4. Write the output for the following program.
   #include <iostream>
   #include <iomanip>
   using namespace std;
   int main() {
      int num = 42;
      cout << setfill('*') << setw(5) << num << endl;
      return 0;
   }
5. Write the output for the following program.
   #include <iostream>
   using namespace std;
   int main() {
      int a = 10;
      int* p = &a;
      int** pp = &p;
       *p = 20;
       **pp = 30;
         int b = 40;
         *pp = &b;
         **pp = 50;
         int* q = new int(60);
         *p = *q;
         delete q;
         q    = nullptr;
         cout << a << " " << b << " " << *p << endl;
         return 0;
     }
  6. Write the output:
     #include <iostream>
     #include <vector>
     #include <algorithm>
     using namespace std;
     int main() {
        vector<int> v1 = {3, 2, 3};
        vector<int> v2 = {4, 5};
         auto it1 = v1.begin() + 1;
         auto it2 = v2.begin() + 1;
         v1.insert(it1, v2.begin(), v2.end());
         v2.insert(it2, v1.begin(), v1.begin() + 2);
         for (int val : v1)
            cout << val << " ";
         cout << endl;
         for (int val : v2)
            cout << val << " ";
         cout << endl;
         return 0;
     }
ROUND- II- ONLINE ASSESSMENT II (CODING ROUND)
There were 2 coding questions
  1. Problem Statement:
     A person is shifting items from one house to another. He can carry at most two items at
     a time, and the total weight of the items he carries in a single move must be less than or
     equal to a given weight limit K. You are given an array weights[] of size N, where each
     element represents the weight of an item. The person wants to carry all items to the new
     house using the minimum number of moves.
     Rules:
     He can carry one or two items per move.
     If an item’s weight is equal to K, it must be carried alone.
     The sum of the weights of the two items carried together must be less than or equal to K.
     Each item must be moved exactly once.
    Write a C++ program to determine the minimum number of moves required to shift all
    the items.
    Input Format:
    First line: Two integers N (number of items) and K (maximum weight that can be carried
    in a move)
    Second line: N space-separated integers representing the weights of the items
    Output Format:
    A single integer: the minimum number of moves required
2. Problem Statement:
    A person is shifting items from one house to another. He can carry at most two items at
    a time, and the total weight of the items he carries in a single move must be less than or
    equal to a given weight limit K. You are given an array weights[] of size N, where each
    element represents the weight of an item. The person wants to carry all items to the new
    house using the minimum number of moves.
    Rules:
    He can carry one or two items per move.
    If an item’s weight is equal to K, it must be carried alone.
    The sum of the weights of the two items carried together must be less than or equal to K.
    Each item must be moved exactly once.
    Write a C++ program to determine the minimum number of moves required to shift all
    the items.
    ________________________________________
    Input Format:
    First line: Two integers N (number of items) and K (maximum weight that can be carried
    in a move)
    Second line: N space-separated integers representing the weights of the items
    ________________________________________
    Output Format:
    A single integer: the minimum number of moves required
    Rules / Explanation:
•   At each spot i, horse receives food Given[i] units of food.
•   To move to the next spot (i+1) %N, the horse consumes food Needed[i] units.
•   The food balance must never go negative during the journey.
•   The tour is circular, so after the last spot, the horse goes back to the first.