CGI interview experience Real time questions & tips from candidates to crack your interview

Associate Software Engineer

CGI
upvote
share-icon
4 rounds | 13 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 4 Months
Topics: Data Structures, Algorithms, Python, System Design, Aptitude, OOPS
Tip
Tip

Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.

Application process
Where: Campus
Eligibility: Above 7 CGPA
Resume Tip
Resume tip

Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.

Interview rounds

01
Round
Medium
Online Coding Test
Duration70 minutes
Interview date22 Nov 2021
Coding problem2

This was an online coding round where we had 2 questions to solve under 70 minutes.

1. Anagram Pairs

Moderate
30m average time
60% success
0/80
Asked in companies
NearbuyAppleAmerican Express

You are given two strings 'str1' and 'str1'.


You have to tell whether these strings form an anagram pair or not.


The strings form an anagram pair if the letters of one string can be rearranged to form another string.

Pre-requisites:

Anagrams are defined as words or names that can be formed by rearranging the letters of another word. Such as "spar" can be formed by rearranging letters of "rasp". Hence, "spar" and "rasp" are anagrams. 

Other examples include:

'triangle' and 'integral'
'listen' and 'silent'
Note:
Since it is a binary problem, there is no partial marking. Marks will only be awarded if you get all the test cases correct. 
Problem approach

Approach : 

1) Sort both strings, so that all the same characters come together.

2) Then loop through both strings together and check each element in both strings one by one.

3) If at any position, the characters are found to be different or if the lengths of the two strings are different, they cannot be anagrams.

4) Otherwise, they will be anagrams.


TC : O(N * log(N) + (M * log(M))), where N and M are the lengths of the two input strings.
SC : O(1)

Try solving now

2. Frog Jump

Easy
30m average time
60% success
0/40
Asked in companies
MicrosoftDunzoCIS - Cyber Infrastructure

There is a frog on the '1st' step of an 'N' stairs long staircase. The frog wants to reach the 'Nth' stair. 'HEIGHT[i]' is the height of the '(i+1)th' stair.If Frog jumps from 'ith' to 'jth' stair, the energy lost in the jump is given by absolute value of ( HEIGHT[i-1] - HEIGHT[j-1] ). If the Frog is on 'ith' staircase, he can jump either to '(i+1)th' stair or to '(i+2)th' stair. Your task is to find the minimum total energy used by the frog to reach from '1st' stair to 'Nth' stair.

For Example
If the given ‘HEIGHT’ array is [10,20,30,10], the answer 20 as the frog can jump from 1st stair to 2nd stair (|20-10| = 10 energy lost) and then a jump from 2nd stair to last stair (|10-20| = 10 energy lost). So, the total energy lost is 20.
Problem approach

Approach : 

1) Declare an array ‘DP’ of size N+1.

2) Set DP[N] as 0.

3) Set DP[N-1] as abs(HEIGHTS[N-1] - HEIGHTS[N-2]).

4) For i in range N-2 to 1:
4.1) Set ONE_JUMP as DP[i+1] + abs(HEIGHTS[i-1]-HEIGHTS[i]).
4.2) Set TWO_JUMP as DP[i+2] + abs(HEIGHTS[i-1]-HEIGHTS[i+1]).
4.3) Set DP[i] as the minimum of ONE_JUMP and TWO_JUMP.

5) Set ‘ANS’ as DP[1].

6) Return ANS.


TC : O(N), where N = number of stairs
SC : O(N)

Try solving now
02
Round
Medium
Video Call
Duration50 Minutes
Interview date22 Nov 2021
Coding problem2

This round had 2 coding questions where I was expected to first explain my approach with proper complexity analysis and then write the pseudo code for both the solutions.

1. Preorder traversal of a BST

Moderate
15m average time
85% success
0/80
Asked in companies
HSBCDisney + HotstarOracle

You have been given an array/list 'PREORDER' representing the preorder traversal of a BST with 'N' nodes. All the elements in the given array have distinct values.

Your task is to construct a binary search tree that matches the given preorder traversal.

A binary search tree (BST) is a binary tree data structure that has the following properties:

• The left subtree of a node contains only nodes with data less than the node’s data.
• The right subtree of a node contains only nodes with data greater than the node’s data.
• Both the left and right subtrees must also be binary search trees.

Note:

It is guaranteed that a BST can be always constructed from the given preorder traversal. Hence, the answer will always exist.
Example:
From PREORDER = [20, 10, 5, 15, 13, 35, 30, 42] , the following BST can be constructed:

example

Problem approach

Approach (Using Recursion) : 

1) Defining the preorder(node, ans) : 
i) If the node is an empty node, we will return from the function.
ii) Insert node value into the ans array.
ii) Now we will traverse to the left subtree.
iv) Create a recursive call preorder(left child of the node, ans).
v) Now we will traverse to the right subtree.
vi) Create a recursive call preorder(right child of the node, ans).

2) We will define an array ans to store the preorder traversal of the given tree.

3) We will call preorder(root, ans).

4) Return the array ans.


//Pseudo Code

vectorans;

void preorder(TreeNode*root)
{
if(root)
{
ans.push_back(root->val);
preorder(root->left);
preorder(root->right);
}
}


TC : O(N), where N = number of nodes in the tree.
SC : O(N)

Try solving now

2. Power Set

Easy
15m average time
85% success
0/40
Asked in companies
AdobeAmazonFacebook

You are given a sorted array of 'N' integers. You have to generate the power set for this array where each subset of this power set is individually sorted.

A set is a well-defined collection of distinct elements. Power set P(ARR) of a set 'ARR' is defined as a set of all possible subsets of 'ARR'.

You have to return the array of subsets. The elements in the subset should be sorted in ascending order. The order of subsets in the array does not matter. Hence there can be more than 1 possible solution for a given array.

For example :
If we are given an array ARR=[1,2,3] then the power set P(ARR) of the set ARR is: [ [], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3] ]
Note :
For every subset 'X' present in power set P(ARR) of set ARR, X must be sorted i.e. in the example above:
P1(ARR) =  [ [], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3] ]
P2(ARR) =  [ [], [1], [1,2,3], [2], [1,2], [3], [1,3], [2,3] ]
P3(ARR) =  [ [], [1], [2], [1,2], [3], [1,3], [2,3], [2,3,1] ]
P1(ARR) and P2(ARR) will be considered correct power sets but P3(ARR) will not be considered correct because there the last subset [2, 3, 1] is not sorted.
Problem approach

Approach (Using Bit Masking) :

1) We have two possibilities either selecting a number in subset or not.

2) A bit can be either 0 or 1, thus we can use this to denote whether the corresponding element belongs to the current subset or not. So each bit pattern will represent a subset. So we will get all the subsets.

3) Let’s say we have a given array ARR.

4) Let ANS = [ [] ] is our answer.

5) Iterate 0<= I <=2^N and do:
5.1) CURR = []

5.2) Iterate over ARR[i] for each 0 <= J < N and do:
If the Jth bit is set in I then include the Jth element to CURR.

5.3) Append CURR to ANS.


//Pseudo Code : 

vector>PowerSet(vectorarr)
{
int n=arr.size();
int total=(1<>ans;
for(int i=0; itmp;
for(int j=0; j {
if(i&(1< tmp.push_back(arr[j]); 
}
ans.push_back(tmp);
}
return ans;
}


TC : O(N*(2^N)), where N = length of the string.
SC : O(N*(2^N))

Try solving now
03
Round
Medium
Video Call
Duration60 Minutes
Interview date22 Nov 2021
Coding problem7

In this round I was first asked a simple coding question related to Linked List and then the interviewer switched to questions related to Python as I told him I had been coding in Python for the last 2 years and so I was tested on my skills in Python and OOPS.

1. Intersection of Linked List

Easy
25m average time
73% success
0/40
Asked in companies
Hewlett Packard EnterpriseSamsungIntuit

You are given two Singly Linked Lists of integers, which may have an intersection point.

Your task is to return the first intersection node. If there is no intersection, return NULL.


Example:-
The Linked Lists, where a1, a2, c1, c2, c3 is the first linked list and b1, b2, b3, c1, c2, c3 is the second linked list, merging at node c1.

alt.txt

Problem approach

Approach :

1) Calculate the length of both the lists, say len1 and len2

2) Get the absolute difference of the lengths, diff = |len1 – len2|

3) Now traverse the long list from the first node till ‘diff’ nodes so that from there onwards both the lists have equal
number of nodes

4) Then traverse both the lists in parallel and check whether a common node is reached (Note that getting a common
node is done by comparing the address of the nodes, not the data)
4.1) If yes, return that node’s data
4.2) If no, return -1


TC : O(N) , where N = max length of the linked list
SC : O(1)

Try solving now

2. Python Question

What are global, protected and private attributes in Python?

Problem approach

1) Global variables are public variables that are defined in the global scope. To use the variable in the global scope inside a function, we use the global keyword.

2) Protected attributes are attributes defined with an underscore prefixed to their identifier eg. _sara. They can still be accessed and modified from outside the class they are defined in but a responsible developer should refrain from doing so.

3) Private attributes are attributes with double underscore prefixed to their identifier eg. __ansh. They cannot be accessed or modified from the outside directly and will result in an AttributeError if such an attempt is made.

3. Python Question

What is the use of self in Python?

Problem approach

Self is used to represent the instance of the class. With this keyword, you can access the attributes and methods of the class in python. It binds the attributes with the given arguments. self is used in different places and often thought to be a keyword. But unlike in C++, self is not a keyword in Python.

4. Python Question

What is the difference between Python Arrays and lists?

Problem approach

1) Arrays in python can only contain elements of same data types i.e., data type of array should be homogeneous. It is a thin wrapper around C language arrays and consumes far less memory than lists.

2) Lists in python can contain elements of different data types i.e., data type of lists can be heterogeneous. It has the disadvantage of consuming large memory.

5. Python Question

What is pickling and unpickling?

Problem approach

Python library offers a feature - serialization out of the box. Serializing an object refers to transforming it into a format that can be stored, so as to be able to deserialize it, later on, to obtain the original object. Here, the pickle module comes into play.

Pickling:
Pickling is the name of the serialization process in Python. Any object in Python can be serialized into a byte stream and dumped as a file in the memory. The process of pickling is compact but pickle objects can be compressed further. Moreover, pickle keeps track of the objects it has serialized and the serialization is portable across versions.
The function used for the above process is pickle.dump().


Unpickling:
Unpickling is the complete inverse of pickling. It deserializes the byte stream to recreate the objects stored in the file and loads the object to memory.
The function used for the above process is pickle.load()

6. Python Question

What is init method in python?

Problem approach

The init method works similarly to the constructors in Java. The method is run as soon as an object is instantiated. It is useful for initializing any attributes or default behaviour of the object at the time of instantiation.

7. Python Question

How does inheritance work in python?

Problem approach

Inheritance gives the power to a class to access all attributes and methods of another class. It aids in code reusability and helps the developer to maintain applications without redundant code. The class inheriting from another class is a child class or also called a derived class. The class from which a child class derives the members are called parent class or superclass.

Python supports different kinds of inheritance, they are:

1) Single Inheritance: Child class derives members of one parent class.

2) Multi-level Inheritance: The members of the parent class, A, are inherited by child class which is then inherited by another child class, B. The features of the base class and the derived class are further inherited into the new derived class, C. Here, A is the grandfather class of class C.

3) Multiple Inheritance: This is achieved when one child class derives members from more than one parent class. All features of parent classes are inherited in the child class.

4) Hierarchical Inheritance: When a parent class is derived by more than one child class, it is called hierarchical inheritance.

04
Round
Easy
HR Round
Duration30 Minutes
Interview date22 Nov 2021
Coding problem2

This is a cultural fitment testing round. HR was very frank and asked standard questions. Then we discussed about my role.

1. Basic HR Question

Tell me something not there in your resume.

Problem approach

If you get this question, it's an opportunity to choose the most compelling information to share that is not obvious from
your resume.

Example :

Strength -> I believe that my greatest strength is the ability to solve problems quickly and efficiently, which makes me
unique from others.

Ability to handle Pressure -> I enjoy working under pressure because I believe it helps me grow and become more
efficient.


Tip : Emphasize why you were inspired to apply for the job. You can also explain that you are willing to invest a great
deal of energy if hired.

These are generally very open ended questions and are asked to test how quick wit a candidate is. So there is
nothing to worry about if you have a good command over your communication skills and you are able to propagate
your thoughts well to the interviewer.

2. Basic HR Question

Why should we hire you ?

Problem approach

Tip 1 : The cross questioning can go intense some time, think before you speak.

Tip 2 : Be open minded and answer whatever you are thinking, in these rounds I feel it is important to have opinion.

Tip 3 : Context of questions can be switched, pay attention to the details. It is okay to ask questions in these round,
like what are the projects currently the company is investing, which team you are mentoring. How all is the work
environment etc.

Tip 4 : Since everybody in the interview panel is from tech background, here too you can expect some technical
questions. No coding in most of the cases but some discussions over the design can surely happen.

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

What is recursion?

Choose another skill to practice
Similar interview experiences
company logo
Associate Software Engineer
4 rounds | 6 problems
Interviewed by CGI
964 views
0 comments
0 upvotes
company logo
Associate Software Engineer
4 rounds | 14 problems
Interviewed by CGI
1186 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 5 problems
Interviewed by CGI
659 views
0 comments
0 upvotes
company logo
SDE
3 rounds | 7 problems
Interviewed by CGI
696 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
Associate Software Engineer
3 rounds | 2 problems
Interviewed by Ernst & Young (EY)
2672 views
0 comments
0 upvotes
company logo
Associate Software Engineer
3 rounds | 15 problems
Interviewed by Ernst & Young (EY)
2347 views
0 comments
0 upvotes
company logo
Associate Software Engineer
4 rounds | 9 problems
Interviewed by NCR Corporation
1475 views
0 comments
0 upvotes