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

Associate Software Engineer

CGI
upvote
share-icon
4 rounds | 14 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 4 Months
Topics: Data Structures, Algorithms, System Design, Java, 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 date28 Apr 2021
Coding problem2

In this round, we had 2 coding questions of Easy to Medium level of difficulty to solve under 70 minutes.

1. Palindromic Substrings

Moderate
20m average time
80% success
0/80
Asked in companies
MicrosoftSalesforceAmazon

You have been given a string STR. Your task is to find the total number of palindromic substrings of STR.

Example :
If the input string is "abbc", then all the possible palindromic substrings would be: ["a", "b", "b", c", "bb"] and hence, the output will be 5 since we have 5 substrings in total which form a palindrome.
Note :
A string is said to be a 'Palindrome' if it is read the same forwards and backwards. 
For example, “abba” is a palindrome, but “abbc” is not.

A 'Substring' is a contiguous sequence of characters within a string. 
For example, "a", "b", "c", "ab", "bc", "abc" are substrings of "abc".
Problem approach

Approach (Using DP) :

1) Create a 2-D dp boolean vector(with all false initially) where dp[i][j] states whether s[i...j] is a palindrome or not .

2) Base Case : For every i from 0 to n-1 fill dp[i][i]=1 ( as a single character is always a palindrome )and increment the
counter where counter=0 initially

3) Now, run 2 loops first one from i=n-1 to i=0 (i.e., tarverse from the back of the string) and the second one from
j=i+1 to n .

4) For every s[i]==s[j] , check if(j-i==1 i.e., if s[i] and s[ j] are two consecutive same letters) or if(dp[i+1][j-1]==1 or not
i.e., if the string s[i+1,....j-1] is palindrome or not .

5) Because if the string s[i+1,....j-1] is a palindrome and s[i]==s[j] then s[i] and s[j] can be appended at the starting
and the ending position of s[i+1,...j-1] and s[i...j] will then be a palindrome , so mark dp[i][j]=1 and increment the
counter

6) Finally return the counter


TC : O(N^2) where N=length of the string s
SC : O(N^2)

Try solving now

2. Pythagorean Triplets

Moderate
35m average time
70% success
0/80
Asked in companies
OYOAmazonErnst & Young (EY)

You are given an array of n integers (a1, a2,....,an), you need to find if the array contains a pythagorean triplet or not.

An array is said to have a pythagorean triplet if there exists three integers x,y and z in the array such that x^2 + y^2 = z^2.

Note
1. The integers x,y and z might not be distinct , but they should be present at different locations in the array i.e if a[i] = x, a[j] = y and a[k] = z, then i,j and k should be pairwise distinct.
2. The integers a,b and c can be present in any order in the given array.
Problem approach

Approach :
1) I solved it in O(N^2) approach .
2) Sort the array
3) Initially map all the elements of the array to their index in a Hash Map or a Hash Set
4) Now , run 2 for loops and for every x^2 + y^2 ,check if there exists a z^2 s.t x^2+y^2=z^2 and the index of z^2 is
different than both the indices of x and y

Try solving now
02
Round
Medium
Video Call
Duration50 Minutes
Interview date28 Apr 2021
Coding problem5

This round had 2 preety simple coding questions followed by some questions from Operating System.

1. Two Sum

Easy
10m average time
90% success
0/40
Asked in companies
Chegg Inc.FacebookAmazon

You are given an array of integers 'ARR' of length 'N' and an integer Target. Your task is to return all pairs of elements such that they add up to Target.

Note:

We cannot use the element at a given index twice.

Follow Up:

Try to do this problem in O(N) time complexity. 
Problem approach

Approach :

1) We can store the frequency of every element in the array in a hashmap.

2) We will loop over every index i, and check the frequency of (Target - ARR[i]) is the hashmap:
2.1) If (Target - ARR[i]) is equal to ARR[i], we will check if frequency of ARR[i] . If it is greater than 1 then we will
decrease the frequency of ARR[i] by 2 and add a pair (ARR[i] , ARR[i]) to our answer.

2.2) Else, if the frequency of ARR[i] and Target - ARR[i] is greater than equal to 1 then we add pair (ARR[i], Target -
ARR[i]) to our answer and decrease the frequency of both by 1.

3) If no valid pairs exist, we will return [[-1,-1]].


TC : O(N), where N=size of the array
SC : O(N)

Try solving now

2. Spiral Matrix

Easy
0/40
Asked in companies
CultfitGoldman SachsDunzo

You are given a N x M matrix of integers, print the spiral path of the matrix.

For example:

Spiral Path

Problem approach

Approach :

spiralPrint(matrix[][], R, C, rows, cols):

1) Check for base cases, i.e. if outside the boundary of the matrix then return.

2) Print the first row from left to right of the matrix i.e from column ‘C’ to ‘cols’, print the elements of the Rth row.

3) Print the last column from top to bottom of the matrix i.e from row ‘R’ to ‘rows’, print the elements of the (cols)th
column.

4) Print the last row from right to left of the matrix i.e from column ‘cols’ to ‘C’, print the elements of the (rows)th row.

5) Print the first column from bottom to top of the matrix i.e from row ‘rows’ to ‘R’, print the elements of the Cth
column.

6) Call the function recursively with the updated values of boundaries, spiralPrint(matrix, R + 1, C + 1, rows - 1, cols -
1).


TC : O(N*M) , where N = number of rows and M = number of columns of the matrix.
SC : O(max(N,M))

Try solving now

3. OS Question

Print 1 to 100 using more than two threads(optimized approach).

Problem approach

Prerequisite to solve this problem : Multithreading

The idea is to create two threads and print even numbers with one thread and odd numbers with another thread.

Below are the steps:

1) Create two threads T1 and T2 , where T1 and T2 are used to print odd and even numbers respectively.

2) Maintain a global counter variable and start both threads.

3) If the counter is even in the Thread T1, then wait for the thread T2 to print that even number. Otherwise, print that
odd number, increment the counter and notify to the Thread T2 .

4)If the counter is odd in the Thread T2, then wait for the thread T1 to print that even number. Otherwise, print that
even number, increment the counter and notify the Thread T1.

4. OS Question

Difference between Process and Program

Problem approach

Process : A Process is an execution of a specific program. It is an active entity that actions the purpose of the
application. Multiple processes may be related to the same program. For example, if we double-click on Google
Chrome browser, we start a process that runs Google Chrome and when we open another instance of Chrome, we
essentially create a second process.


Program : A Program is an executable file which contains a certain set of instructions written to complete the specific
job or operation on your computer. For example, Google browser chrome.exe is an executable file which stores a set
of instructions written in it which allows us to open the browser and explore web pages.


Major Differences b/w Process and Program :

1) Process is an executing part of a program whereas a program is a group of ordered operations to achieve a
programming goal.

2) The process has a shorter and minimal lifespan whereas program has a longer lifespan.

3) Process contains many resources like a memory address, disk, printer while Program needs memory space on the
disk to store all instructions.

4) When we distinguish between process and program, Process is a dynamic or active entity whereas Program is a
passive or static entity.

5) To differentiate program and process, Process has considerable overhead whereas Program has no significant
overhead cost.

5. OS Question

Difference between Process and Thread

Problem approach

Process : A process is the execution of a program that allows us to perform the appropriate actions specified in a
program. It can be defined as an execution unit where a program runs. The OS helps us to create, schedule, and
terminates the processes which is used by CPU. The other processes created by the main process are called child
process.


Thread : Thread is an execution unit that is part of a process. A process can have multiple threads, all executing at
the same time. It is a unit of execution in concurrent programming. A thread is lightweight and can be managed
independently by a scheduler. It helps us to improve the application performance using parallelism.


Major Differences b/w Process and Thread :

1) Process means a program is in execution, whereas thread means a segment of a process.
2) A Process is not Lightweight, whereas Threads are Lightweight.
3) A Process takes more time to terminate, and the thread takes less time to terminate.
4) Process takes more time for creation, whereas Thread takes less time for creation.
5) Process likely takes more time for context switching whereas as Threads takes less time for context switching.
6) A Process is mostly isolated, whereas Threads share memory.
7) Process does not share data, and Threads share data with each other.

03
Round
Medium
Video Call
Duration60 Minutes
Interview date28 Apr 2021
Coding problem6

This round had 1 coding question where I was just asked to write the pseudo code. This was followed by some discussions on OOPS and then the interviewer asked me some questions related to DBMS and Java and ended the interview with a simple question on SQL.

1. Remove Vowels

Easy
10m average time
90% success
0/40
Asked in companies
OptumPractoCGI

You are given a string STR of length N. Your task is to remove all the vowels present in that string and print the modified string.

English alphabets ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ are termed as vowels. All other alphabets are called consonants.

Note: You have to only remove vowels from the string. There will be no change in the relative position of all other alphabets.

For example:
(i)  If the input string is 'CodeGeek', the output should be CdGk after removing ‘o’ and ‘e’.

(ii) If the input string is 'Odinson', the output should be 'dnsn' after removing ‘o’ and ‘i’. 
Problem approach

Approach : 

1) Create a new empty string, say RES

2) Iterate through original string STR and check if the current alphabet is a vowel or not.
--If it is not a vowel, append it to the back of RES
--If it is a vowel do nothing

3) The RES string now contains the desired string without vowels.

TC : O(N), where N = length of the string
SC : O(N)

Try solving now

2. DBMS Question

What is the main difference between UNION and UNION ALL?

Problem approach

UNION and UNION ALL are used to join the data from 2 or more tables but UNION removes duplicate rows and picks
the rows which are distinct after combining the data from the tables whereas UNION ALL does not remove the
duplicate rows, it just picks all the data from the tables.

3. DBMS Question

What is Cursor? How to use a Cursor?

Problem approach

A database cursor is a control structure that allows for the traversal of records in a database. Cursors, in addition,
facilitates processing after traversal, such as retrieval, addition, and deletion of database records. They can be
viewed as a pointer to one row in a set of rows.

Working with SQL Cursor :

1) DECLARE a cursor after any variable declaration. The cursor declaration must always be associated with a
SELECT Statement.

2) Open cursor to initialize the result set. The OPEN statement must be called before fetching rows from the result
set.

3) FETCH statement to retrieve and move to the next row in the result set.

4) Call the CLOSE statement to deactivate the cursor.

5) Finally use the DEALLOCATE statement to delete the cursor definition and release the associated resources.

4. OOPS Question

Explain the use of final keyword in variable, method and class.

Problem approach

In Java, the final keyword is used as defining something as constant /final and represents the non-access modifier.

1) final variable :
i) When a variable is declared as final in Java, the value can’t be modified once it has been assigned.

ii) If any value has not been assigned to that variable, then it can be assigned only by the constructor of the class.


2) final method :
i) A method declared as final cannot be overridden by its children's classes.

ii) A constructor cannot be marked as final because whenever a class is inherited, the constructors are not inherited.
Hence, marking it final doesn't make sense. Java throws compilation error saying - modifier final not allowed here


3) final class :
i) No classes can be inherited from the class declared as final. But that final class can extend other classes for its
usage.

5. Java Question

How many types of memory areas are allocated by JVM?

Problem approach

1) Class(Method) Area: Class Area stores per-class structures such as the runtime constant pool, field, method data, and the code for methods.

2) Heap: It is the runtime data area in which the memory is allocated to the objects

3) Stack: Java Stack stores frames. It holds local variables and partial results, and plays a part in method invocation and return. Each thread has a private JVM stack, created at the same time as the thread. A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.

4) Program Counter Register: PC (program counter) register contains the address of the Java virtual machine instruction currently being executed.

5) Native Method Stack: It contains all the native methods used in the application.

6. SQL Question

Write a query that joins two tables A and B having common attribute ID and selects records(ID_NAME) that have
matching ID values in both tables.

Problem approach

SELECT A.ID_Name, B.ID_Name
FROM A
INNER JOIN B ON A.ID=B.ID;

04
Round
Easy
HR Round
Duration30 Minutes
Interview date28 Apr 2021
Coding problem1

This was a Technical Cum HR round where I was first asked some basic OOPS related concepts and then we discussed
about my expectations from the company , learnings and growth in the forthcomig years. I would suggest be honest and
try to communicate your thoughts properly in these type of rounds to maximise your chances of getting selected.

1. Basic HR Question

Tell me something about yourself?

Problem approach

Tip 1 : Prepare the points that you will speak in your introduction prior to the interview.
Tip 2 : Tell about your current cgpa, achievements and authenticated certification
Tip 3 : I told about my role in current internship and what all I do

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 | 13 problems
Interviewed by CGI
920 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