Log In

Don't have an account? Sign up now

Lost Password?

Sign Up

Next

Capgemini Interview Guide

All about Capgemini interview

Capgemini Hiring Process 2025 – Complete & Simple Guide for Freshers

If you are planning to sit for Capgemini Hiring 2025, then this guide will help you understand everything — the process, salary, interview rounds, roles offered and what exactly Capgemini looks for in a fresher candidate.

Capgemini hires thousands of engineering graduates every year through on-campus and off-campus drives, mainly for three roles:

  • Analyst
  • Senior Analyst
  • Star Analyst

Let’s break down the complete hiring process in a very easy way.


🚀 Total Hiring Rounds at Capgemini

Capgemini follows a 3-round hiring process, but the first round itself has multiple tests inside it.

1. Online Assessment (Most Important & Highly Eliminating)

The Online Assessment includes the following tests:

  • Technical Test
  • English Communication Test
  • Game-Based Aptitude Test
  • Behavioral Competency Test
  • Spoken English Test
  • Coding Test

Duration: 145 minutes (approx)

More than 75% candidates are eliminated in this round itself.
To be safe, you should aim for 60%+ in each section because Capgemini checks sectional cutoffs, not just the total score.


2. Technical Interview Round

This is the toughest round in the whole process.
More than 92% candidates who reach here get eliminated.

You will be tested deeply on:

  • DSA (basic + intermediate)
  • DBMS (queries, normalization, ACID properties)
  • OOPs concepts
  • Computer Networks basics
  • Projects (be very confident)
  • Coding problem (sometimes)
  • Internship experience (if any)
  • Certifications (they ask questions from whatever you mention)

⏳ Duration: 50 minutes to 1 hour
⚠️ If your interview ends in just 15–20 mins, chances are you are not shortlisted for HR.


3. HR Interview Round

This round is mostly easy, but not 100% guaranteed.
Even after clearing technical, you can be rejected if they feel you are not a cultural fit.

Common HR questions at Capgemini:

  • Tell me about yourself
  • Why should we hire you?
  • Where do you see yourself in the next 5 years?
  • Are you willing to relocate?
  • What are your strengths and weakness?
  • Tell me about your hobbies
  • Basic psychometric or situation-based questions
  • Sometimes puzzles

Most students clear this round unless there is a major communication issue or the panel finds red flags.


💼 Roles Offered by Capgemini (Freshers)

Capgemini hires freshers for three profiles:

RolePackage (Approx)Mode of Hiring
Analyst₹4.25 LPAOn & Off Campus
Senior Analyst₹5.75 LPAMostly On-Campus
Star Analyst₹7.50 LPAOnly On-Campus & Limited

⚠️ Note: Packages may change every year depending on market conditions, your college tier, and the city you get posted in.


📦 Salary Breakdown (Explained Simply)

Capgemini provides various benefits along with the salary such as:

  • Basic Pay
  • Annual Bonus
  • PF & Gratuity
  • Medical Insurance
  • Internet/Travel Allowances
  • Shift Allowance (if applicable)

Salary varies based on:

  • Location
  • College Tier
  • Role (Analyst/Senior/Star Analyst)

Generally Tier-2 colleges get similar packages, but top colleges sometimes get slightly better CTC.


📝 Capgemini Hiring Process (Step-by-Step)

1. Online Assessment

Most important and toughest screening stage.
Clearing all sections is compulsory.

2. Technical Interview

Focus on coding, projects, DSA, DBMS, OOPs.

3. HR Interview

Checks cultural fit, communication, confidence, clarity of thoughts.


🏢 About Capgemini (Short Overview for Interviews)

  • Founded: 1 October 1967
  • Founder: Serge Kampf
  • Headquarters: Paris, France
  • Industry: IT Services, Consulting, Outsourcing
  • Provides services in:
    • Cloud
    • AI & Automation
    • Cybersecurity
    • Digital engineering
    • Software development
    • Business consulting

Capgemini is known for being a mass recruiter and for giving freshers a good work-life balance compared to many IT companies.


🎯 Tips to Crack Capgemini Hiring 2025

  • Prepare DSA basics very well (arrays, strings, sorting, searching).
  • Practice SQL queries daily.
  • Focus on OOPs concepts — very important in interviews.
  • Be honest and confident while explaining your projects.
  • Improve communication skills for HR and Spoken English test.
  • Practice previous year game-based aptitude questions.
  • Don’t write anything unnecessary in your resume because they will ask from everything.

50 most asked technical question

1. What is the use of break statement?

It immediately stops the loop and transfers control outside it.

2. What is a unique key?

A constraint that ensures each value in a column is unique.

3. What is a static variable?

A variable that keeps its value between function calls and has global lifetime.

4. What is Machine Learning?

A method where computers learn patterns from data automatically.

5. What is printf() and scanf()?

printf prints output; scanf takes user input.

6. What is IIoT?

Industrial IoT — IoT used in large-scale industrial operations.

7. How many programming languages do you know?

Mention the languages you know with proper confidence levels.

8. What is a pointer in C?

A variable that stores the memory address of another variable.

9. How is Raspberry Pi used in IoT?

As a mini-computer to run IoT applications and connect sensors.

10. What is GUI?

A visual interface using icons, windows, and buttons.

11. What is DBMS?

Software that stores, manages, and organizes databases.

12. What is Ethical Hacking?

Finding security weaknesses legally to improve protection.

13. What is Recursion?

A function calling itself repeatedly until a base condition.

14. What is method overloading?

Same method name, different parameters.

15. What is a NULL pointer?

A pointer that doesn’t point to any memory location.

16. What is interpreted language?

Code executed line-by-line by an interpreter.

17. What do you like most about IT?

Fast innovation, learning opportunities, and growth.

18. What is ACID property?

Ensures reliable transactions: Atomic, Consistent, Isolated, Durable.

19. What is a relationship in DBMS?

Logical connection between tables (1–1, 1–many, many–1, etc.).

20. DELETE vs TRUNCATE

DELETE removes specific rows; TRUNCATE clears whole table quickly.

21. What is slicing in Python?

Extracting a subpart of a list/tuple using [start:end:step].

22. What is pass in Python?

A placeholder statement that does nothing.

23. What is a command line argument?

Arguments passed to a program at execution time.

24. JVM, JDK, JRE

JVM runs Java; JRE provides runtime; JDK is for developing Java.

25. What is Raspberry Pi?

A small computer for learning coding and IoT.

26. What is an infinite loop?

A loop that runs forever due to missing termination.

27. What is ‘this’ keyword?

Refers to the current object in Java.

28. What is swapcase()?

Converts upper to lower and lower to upper case.

29. What is a neural network?

A machine learning model inspired by the human brain.

30. Training set vs Test set

Training set teaches the model; test set checks accuracy.

31. What is an operator?

A symbol that performs an operation (e.g., +, -, >).

32. What is open-source hardware?

Hardware whose design is publicly shared.

33. What is DNS?

Converts domain names into IP addresses.

34. What is LAN?

Local network within a small area like an office or home.

35. What is a class and object?

Class is a blueprint; object is its instance.

36. How IoT works?

Sensors → Data → Cloud → Analysis → Action.

37. What is final variable?

A variable whose value cannot be changed after assignment.

38. What is SQL?

A language to access and manage databases.

39. What is a dangling pointer?

A pointer pointing to freed or invalid memory.

40. What is a foreign key?

A field linking one table to another’s primary key.

41. Private vs Special IP

Private IP used internally; special IPs like 127.0.0.1 are reserved.

42. What is VPN?

A secure private network over the public internet.

43. What is Deep Learning?

ML using multi-layer neural networks.

44. How to restrict inheritance?

Use final keyword or private constructors.

45. What is SQL query?

A command to fetch or modify data in a database.

46. What is a Python decorator?

A function that modifies the behavior of another function.

47. What is Solution Design Document?

A detailed technical plan for a project.

48. List vs Tuple

Lists are changeable; tuples are fixed.

49. What is enumeration?

Interface used for iterating over collections.

50. What are table, field, record?

Table = entire data
Field = column
Record = row

51. What is NLP?

AI that helps computers understand human language.

52. How do you improve tech skills?

By practice, courses, projects, and reading.

53. Describe your recent project.

Use : Problem → Approach → Tech → Outcome.

54. Call by value vs Call by reference

Value passes a copy; reference passes the address.

55. What is Real-Time OS?

OS that processes data instantly without delays.

56. What is open-source?

Publicly available source code.

57. Real-life applications of NLP

Chatbots, translation, voice assistants.

58. What is multi-programmed OS?

Runs multiple programs at the same time.

59. What is Python self keyword?

Represents the current object inside a class.

60. What is Arduino?

Microcontroller board for IoT and electronics.

61. What are SQL constraints?

Rules applied on columns (NOT NULL, UNIQUE, etc.).

62. Production deployment process

Steps to release code using Agile or DevOps methods.

63. IP vs MAC

IP = logical address; MAC = physical hardware address.

64. What is static method?

Method that belongs to the class, not the object.

65. What is IoT?

Network of devices that communicate data.

66. What is a field?

A column in a table.

67. What is STAR method?

Situation, Task, Action, Result — used in interview answers.

68. What is JDK?

Java Development Kit containing compiler + JRE.

69. What is consistency in ACID?

Ensures a transaction keeps the database valid.

70. What is operator precedence?

Defines the order in which operators execute.

71. Why is Java platform independent?

Because it runs on JVM using bytecode.

72. What is a far pointer?

Pointer that can access a larger memory area.

73. What is a NULL pointer?

Pointer with no assigned memory (points to nothing).

74. What is a test set?

Dataset used to evaluate a trained model.

75. Explain IP vs MAC again in one line.

IP = location; MAC = identity of the device.

20 most asked Capgemini question

Question 1:

What is FTP?
Answer:
File Transfer Protocol or FTP, is an application layer protocol in a TCP/IP based network.
It is used to send files from one computer to another over the internet, by having one computer act as the server.


Question 2:

What is Polymorphism?
Answer:
It is the property by which a single action can be performed in multiple ways. It is an important OOPS concept.


Question 3:

What is SQL?
Answer:
SQL or Structured Query Language is used in managing a relational database. SQL is the language of database, and is used for extracting and organizing data in a database for analysis.


Question 4:

What is Data Structure?
Answer:
Data Structure is a way to organize data in memory. Data Structure is of two types:

  • Primitive data types
  • Non Primitive data types

Question 5:

What is JAVA string pool?
Answer:
Java string pool is a pool of strings that is stored in a memory heap. It is also known as String Intern Pool or String Constant Pool.
Two ways to create a string:

  • Using string literal
  • Using new keyword

Question 6:

Difference between Primary key and Unique Key.
Answer:
Primary key uniquely identifies each record and cannot contain NULL.
Unique key also ensures uniqueness but can contain a single NULL value.


Question 7:

What is shallow copy and deep copy in JAVA?
Answer:
Shallow Copy: Copies the object but not its inner objects; both reference the same memory.
Deep Copy: Copies both object and its inner objects; completely independent of original.


Question 8:

What is DNS?
Answer:
DNS converts domain names into IP addresses that systems can understand.


Question 9:

What is RDBMS?
Answer:
Relational Database Management System is used to manage relational databases. Examples: MySQL, Oracle, IBM DB2.


Question 10:

What is the #pragma directive?
Answer:
It provides additional compiler instructions.
Types: #pragma startup, #pragma exit, #pragma warn, #pragma GCC dependency, etc.


Question 11:

What is scanf()?
Answer:
scanf() reads formatted data from the input stream and stores it into the given arguments.


Question 12:

What is multilevel inheritance?
Answer:
An inheritance type where a child class inherits from a parent class, and then acts as a parent for another child class.


Question 13:

Difference between new() and malloc().
Answer:
new() initializes memory and calls constructor (C++); malloc() allocates raw memory (C).


Question 14:

Difference between dataset.clone() and dataset.copy().
Answer:
clone() copies structure without data;
copy() copies both structure and data.


Question 15:

Difference between class and structure in C++.
Answer:
Class members are private by default;
Structure members are public by default.


Question 16:

What is HTML5?
Answer:
A markup language used for creating web pages. It is the fifth version recommended by W3C.


Question 17:

What is Cloud Computing?
Answer:
Cloud computing uses the internet to store, manage, and process data on remote servers.


Question 18:

What is memory leak in C?
Answer:
Memory leak occurs when allocated memory is not released, causing performance issues.


Question 19:

What is xrange() in Python?
Answer:
Used in Python2 to generate a sequence of numbers, similar to range() in Python3.


Question 20:

What are the features of an array?
Answer:

  • Same datatype elements
  • Saved contiguously in memory
  • Default uninitialized
  • Can be 1D or 2D

Question 21:

What is DROP, DELETE and TRUNCATE?
Answer:
DROP – removes table
DELETE – removes records
TRUNCATE – removes rows but keeps structure


Question 22:

What is Dynamic Host Configuration Protocol (DHCP)?
Answer:
DHCP automatically assigns IP address, subnet mask, and gateway to devices.


Question 23:

What is public static void main(String[] args) in Java?
Answer:
The main entry point for Java programs.
public – accessible everywhere
static – no object needed
void – no return
main – starting method
args – command line arguments


Question 24:

Basic concepts of OOPS
Answer:

  • Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism

Question 25:

Difference between primary key and secondary key.
Answer:
Primary key uniquely identifies a record;
Secondary key is a non-unique key used for indexing/searching.


Question 26:

What is NumPy?
Answer:
A Python library used for scientific and numerical computing.


Question 27:

Why should arrays not be used to implement a Queue?
Answer:

  • Memory waste
  • Fixed size makes flexible queue implementation difficult

Question 28:

Reserved words in Java
Answer:
Words that cannot be used as identifiers, such as: abstract, boolean, break, assert, byte, etc.


Question 29:

What is a loop? What is a nested loop?
Answer:
Loop: A set of instructions that repeat until a condition is met.
Nested loop: A loop inside another loop.


Question 30:

What is UNION and UNION ALL?
Answer:
UNION removes duplicates;
UNION ALL keeps duplicates.

Capgemini coding question in interview (reading)

Question 1:

Consider an unsorted array A of size N containing only positive integers. The task is to identify a contiguous subarray whose elements sum up to a given target number S. Your objective is to determine the left and right indices (1-based indexing) of the identified subarray.

Write a function or algorithm to solve this problem efficiently.

Example:

Input:

N = 5, S = 12

A[] = {1,2,3,7,5}

Output: 2 4

Explanation: The sum of elements 

from 2nd position to 4th position 

is 12.

Input:

N = 10, S = 15

A[] = {1,2,3,4,5,6,7,8,9,10}

Output: 1 5

Explanation: The sum of elements 

from 1st position to 5th position

is 15.


Question 2:

Consider an array of distinct integers. Your task is to determine and count all triplets in the array such that the sum of two elements in the triplet is equal to the third element.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: 

N = 4 

arr[] = {1, 5, 3, 2}

Output: 2 

Explanation: There are 2 triplets:

 1 + 2 = 3 and 3 +2 = 5

Input: 

N = 3

arr[] = {2, 3, 4}

Output: 0

Explanation: No such triplet exits


Question 3:

You are given two sorted arrays, arr1[] and arr2[], both in non-decreasing order. The goal is to merge these arrays in sorted order without using any additional space. Additionally, modify arr1 to contain the first N elements of the merged array and modify arr2 to contain the last M elements.

Write a function or algorithm to achieve this in an efficient manner.

Example:

Input: 

n = 4, arr1[] = [1 3 5 7] 

m = 5, arr2[] = [0 2 6 8 9]

Output: 

arr1[] = [0 1 2 3]

arr2[] = [5 6 7 8 9]

Explanation:

After merging the two 

non-decreasing arrays, we get, 

0 1 2 3 5 6 7 8 9.


Question 4:

Given a string S, your task is to find the longest palindromic substring within it. A palindromic substring is defined as a substring that reads the same backward as forward. Formally, a string S is considered a palindrome if reverse(S) is equal to S. In case of multiple palindromic substrings with the same length, return the substring that occurs first (with the least starting index).

Write a function or algorithm to efficiently solve this problem.

Example:

Input:

S = “aaaabbaa”

Output: aabbaa

Explanation: The longest Palindromic

substring is “aabbaa”.


Question 5:

You are provided with two strings, a and b. The objective is to determine whether the string b can be obtained by rotating (in any direction) the string a by exactly 2 places.

Write a function or algorithm to efficiently solve this problem.

Example:

Input:

a = amazon

b = azonam

Output: 

1

Explanation: 

amazon can be rotated anticlockwise by two places, which will make it as azonam.


Question 6:

Given a string in roman no format (s)  your task is to convert it to an integer . Various symbols and their values are given below.

I 1

V 5

X 10

L 50

C 100

D 500

M 1000

Example:

Input:

s = V

Output: 5

Input: s = III 

Output: 3


Question 7:

Given two strings, a and b, both consisting of lowercase characters, your task is to determine whether these two strings are anagrams of each other. An anagram of a string is another string that contains the same characters, with the only difference being the order of characters.

Write a function or algorithm to efficiently solve this problem.

Example:

Input:

a = “listen”

b = “silent”

Output:

Are Anagrams: True

Explanation:

The strings “listen” and “silent” are anagrams of each other as they contain the same characters.


Question 8:

Given a string S, your objective is to determine the length of the longest substring where all characters are distinct.

Write a function or algorithm to efficiently solve this problem.

Example:

Input:

S = “abcabcbb”

Output:

Length of Longest Substring: 3

Explanation:

The longest substring with distinct characters is “abc,” with a length of 3.


Question 9:

Consider a singly linked list with N nodes. Your task is to identify and print the middle node of the linked list. In the case where the number of nodes, N, is even, print the second middle element.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: LinkedList: 1->2->3->4->5

Output: 3 

Explanation:  Middle of linked list is 3.

Input: Linked List: 1 -> 2 -> 3 -> 4 -> 5 -> 6

Output: Middle Node: 4

Explanation: In this case, as N is even, the second middle element is 4.


Question 10:

Consider a linked list with N nodes. Your objective is to determine whether the linked list contains a loop. It’s important to note that the linked list may include self-loops.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: Linked List: 1 -> 2 -> 3 -> 4 -> 5

Output: Contains Loop: False

Explanation: The linked list doesn’t contain any loops.

Input: Linked List: 1 -> 2 -> 3 -> 4 -> 5 -> 2 (self-loop)

Output: Contains Loop: True

Explanation: In this case, the linked list contains a loop with node 2 pointing back to itself.


Question 11:

Consider a linked list with N nodes. Your task is to reverse the order of the nodes in the linked list.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: Linked List: 1 -> 2 -> 3 -> 4 -> 5

Output: Reversed Linked List: 5 -> 4 -> 3 -> 2 -> 1

Explanation: The linked list has been reversed to have 5 as the new head.


Question 11:

You are given a singly linked list of size N. Your objective is to perform a left shift on the linked list by k nodes, where k is a positive integer not exceeding the length of the linked list.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: N = 5

value[] = {2, 4, 7, 8, 9}

k = 3

Output: 8 9 2 4 7

Explanation:

Rotate 1: 4 -> 7 -> 8 -> 9 -> 2

Rotate 2: 7 -> 8 -> 9 -> 2 -> 4

Rotate 3: 8 -> 9 -> 2 -> 4 -> 7


Question 12:

Consider an array arr[ ] of size N containing elements. Your task is to determine the next greater element for each element of the array in the order of their appearance.

The next greater element for an element in the array is defined as the nearest element on the right that is greater than the current element. If there is no element to the right that is greater than the current element, then the next greater element for the current element is -1. Specifically, the next greater element for the last element in the array is always -1.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: arr[ ] = [4, 5, 2, 10, 8]

Output: Next Greater Elements: [5, 10, 10, -1, -1]

Explanation:

– The next greater element for 4 is 5.

– The next greater element for 5 is 10.

– The next greater element for 2 is 10.

– The next greater element for 10 is not found, so it is -1.

– The next greater element for 8 is not found, so it is -1.


Question 13:

You are required to implement a queue using two stacks, denoted as s1 and s2. Two types of queries are defined for this queue:

(i) 1 x: This type of query indicates pushing element ‘x’ into the queue.

(ii) 2: This type of query indicates popping an element from the queue and printing the popped element. If there is no element in the queue, return -1.

Write a function or algorithm to efficiently implement the described queue using two stacks.

Example:

Input:

1 5

1 10

2

1 7

2

Output:

5

10

Explanation:

– The first query (1 5) pushes 5 into the queue.

– The second query (1 10) pushes 10 into the queue.

– The third query (2) pops the front element (5) from the queue and prints it.

– The fourth query (1 7) pushes 7 into the queue.

– The fifth query (2) pops the front element (10) from the queue and prints it.


Question 14:

Given N elements, your objective is to implement a stack in such a way that you can retrieve the minimum element in O(1) time.

Write a function or algorithm to efficiently implement this stack.

Example:

Input:

Push 3

Push 5

Get Minimum  // Output: 3

Push 2

Get Minimum  // Output: 2

Pop

Get Minimum  // Output: 3

Explanation:

– The first query pushes 3 into the stack.

– The second query pushes 5 into the stack.

– The third query retrieves the minimum element, which is 3.

– The fourth query pushes 2 into the stack.

– The fifth query retrieves the minimum element, which is now 2.

– The sixth query pops an element from the stack.

– The seventh query retrieves the minimum element, which is 3.


Question 15:

You are provided with an input stream A consisting of n characters, where each character is a lowercase alphabet. While reading characters from the stream, your task is to identify, for each position i (0 ≤ i < n), the first character that appears only once in the stream up to that point. If there are multiple characters that have appeared only once, you should identify the first one among them. If there is no such character, append ‘#’ to the answer.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: Stream: “abacabad”

Output: “abbdddc”

Explanation:

– For position 0: ‘a’ is the first character, so ‘a’ is the answer.

– For position 1: ‘b’ is the first character, so ‘b’ is the answer.

– For position 2: ‘a’ appears twice, so ‘b’ is the first non-repeating character.

– For position 3: ‘c’ is the first character, so ‘c’ is the answer.

– For position 4: ‘a’ appears twice, so ‘c’ is the first non-repeating character.

– For position 5: ‘b’ appears twice, so ‘c’ is the first non-repeating character.

– For position 6: ‘a’ appears twice, so ‘c’ is the first non-repeating character.

– For position 7: ‘d’ is the first character, so ‘d’ is the answer.


Question 16:

Consider an array arr[] of size N and an integer K. Your task is to determine the maximum value for each contiguous subarray of size K.

Write a function or algorithm to efficiently solve this problem.

Example:

Input:

Array: [1, 3, 4, 2, 6, 7]

K: 3

Output:

Maximum Values: [4, 4, 6, 7]

Explanation:

– For the first contiguous subarray [1, 3, 4], the maximum value is 4.

– For the second contiguous subarray [3, 4, 2], the maximum value is 4.

– For the third contiguous subarray [4, 2, 6], the maximum value is 6.

– For the fourth contiguous subarray [2, 6, 7], the maximum value is 7.


Question 17:

Consider a grid of dimension nxm where each cell can have values 0, 1, or 2, with the following interpretations:

0: Represents an empty cell.

1: Represents a cell with fresh oranges.

2: Represents a cell with rotten oranges.

Your task is to determine the earliest time after which all the oranges in the grid will be rotten. A rotten orange at index [i, j] can rot other fresh oranges at indexes [i-1, j], [i+1, j], [i, j-1], [i, j+1] (up, down, left, and right) in unit time.

Write a function or algorithm to efficiently solve this problem.

Example:

Input:

Grid:

[[2, 1, 0],

[1, 1, 1],

[0, 1, 2]]

Output:

Earliest Time: 4

Explanation:

After 4 units of time, all the oranges in the grid will be rotten.


Question 18:

You are given an array Arr[] of N integers. Your task is to identify the contiguous sub-array (containing at least one number) with the maximum sum and return its sum.

Write a function or algorithm to efficiently solve this problem.

Example:

Input:

Array: [-2, 1, -3, 4, -1, 2, 1, -5, 4]

Output:

Maximum Sum: 6

Explanation:

The contiguous sub-array [4, -1, 2, 1] has the maximum sum, which is 6.


Question 19:

Consider an array of size N-1 containing distinct integers in the range of 1 to N. Your task is to find the missing element in the array.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: Array: [1, 2, 4, 6, 3, 7, 8]

Output: Missing Element: 5

Explanation: The missing element in the array is 5.


Question 20:

You are provided with a sorted array of positive integers. Your objective is to rearrange the array elements alternatively, such that the first element is the maximum value, the second is the minimum value, the third is the second maximum, the fourth is the second minimum, and so on. It is crucial to modify the original array itself without using any extra space.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: Sorted Array: [1, 2, 3, 4, 5, 6, 7, 8, 9]

Output: Modified Array: [9, 1, 8, 2, 7, 3, 6, 4, 5]

Explanation: The original array is rearranged alternatively as described.


Question 21:

You are provided with an array of integers. Your task is to find the Inversion Count in the array.

Inversion Count indicates how far (or close) the array is from being sorted. If the array is already sorted, the inversion count is 0. In the case of a completely reversed array, the inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: Array: [2, 4, 1, 3, 5]

Output: Inversion Count: 3

Explanation: The inversions in the array are (2, 1), (4, 1), and (4, 3), resulting in a total inversion count of 3.


Question 22:

Consider an array A of n positive numbers. Your objective is to find the first equilibrium point in the array. An equilibrium point is an index (or position) such that the sum of all elements before that index is the same as the sum of elements after it. Return the equilibrium point in 1-based indexing. If no equilibrium point exists, return -1.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: Array: [1, 3, 5, 2, 2]

Output: Equilibrium Point: 3

Explanation:

The equilibrium point is at index 3 (1-based), where the sum of elements before (1+3) is equal to the sum of elements after (2+2).


Question 23:

You are given an array A of positive integers. Your goal is to find the leaders in the array. An element in the array is considered a leader if it is greater than or equal to all the elements to its right side. The rightmost element is always considered a leader.

Write a function or algorithm to efficiently solve this problem.

Example:

Input: Array: [16, 17, 4, 3, 5, 2]

Output: Leaders: [17, 5, 2]

Explanation:

The leaders in the array are 17 (greater than all elements to its right), 5 (greater than 2 to its right), and 2 (rightmost element).


Question 24:

Write a function that takes a list sorted in non-decreasing order and deletes any duplicate nodes from the list. The list should only be traversed once. 

For example if the linked list is 11->11->11->21->43->43->60 then removeDuplicates() should convert the list to 11->21->43->60. 


Question 25:

Given a doubly linked list, devise a function to perform an ascending order sort on the elements using the merge sort algorithm. Implement the necessary steps to ensure the resulting doubly linked list is in increasing order. As an example, demonstrate the transformation of a given doubly linked list into the sorted form, e.g., {2, 4, 8, 10}. Provide the algorithm and steps involved in the sorting process.


Question 26:

You have been given a string S of length N. The given string is a binary string which consists of only 0’s and ‘1’s. Ugliness of a string is defined as the decimal   number that this binary string represents.

Example:

“101” represents 5.

“0000” represents 0.

“01010” represents 10.


Question 27:

Khaled has an array A of N elements. It is guaranteed that N is even. He wants to choose at most N/2 elements from array A. It is not necessary to choose consecutive elements.  Khaled is interested in XOR of all the elements he chooses. Here, XOR denotes the bitwise XOR operation. 

Example:

If A=[2,4,6,8], then khaled can choose the subset [2,4,8] to achieve XOR=(2 XOR 4 XOR 8)=14.

Khaled wants to maximize the XOR of all the elements he chooses. Your task is to help khaled to find the max XOR of a subset that he can achieve by choosing at most N/2 elements?


Question 28:

Given a tree consisting of n vertices, each vertex is either colored black or white. The task is to compute for each vertex v, the maximum difference between the number of white and the number of black vertices if a subtree of the given tree is chosen that contains the vertex v.

Example:

Input: n = 9, color = { 0, 1, 1, 1, 0, 0, 0, 0, 1 }, edges = { { 1, 2 }, { 1, 3 }, { 3, 4 }, { 3, 5 }, { 2, 6 }, { 4, 7 }, { 6, 8 }, { 5, 9 } }

Output: 2 2 2 2 2 1 1 0 2

Input: n = 4, color = { 0, 0, 1, 0}, edges = {{1, 2}, {1, 3}, {1, 4}}

Output: 0 -1 1 -1


Question 29:

Create a function that takes an array A[] composed of only 0s, 1s, and 2s. The goal is to sort the array such that all 0s appear first, followed by all 1s, and finally, all 2s. Implement the function to achieve this specific ordering of elements in the array.

Example:

Input: {0, 1, 2, 0, 1, 2}

Output: {0, 0, 1, 1, 2, 2}

Input: {0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1}

Output: {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2}


Question 30:

Consider a string array S and the objective is to determine the lexicographically smallest string that can be constructed by selecting a single character from each string in the array S. Formulate the steps or algorithm to find this lexicographically smallest string based on the given criteria

Example:

Input: S = [“xy”, “fd”]

Output: “dx”

Explanation: The possible strings formed by extracting a single character from each string are [“xf”, “fx”, “xd”, “dx”, “yf”, “fy”, “yd”, “dy”]. The lexicographically smallest string obtained is “dx”.

Leave a Comment

    🚀 Join Common Jobs Pro — Referrals & Profile Visibility Join Now ×
    🔥