IBM Interview Questions

IBM Interview Questions

IBM is a global technology business located in Armonk, New York, in America, and it has operations in more than 171 countries. CTR (Computing-Tabulating-Recording) Company was formed by trust merchant Charles Ranlett in 1911 in Endicott, New York. It was renamed as “International Business Machines” in 1924. IBM is a global corporation producing and distributing computer hardware, middleware, and software. IBM also focuses on hosting and consulting services in diverse fields, from mainframe computers to nanotechnology. In 1951, IBM started in India, with it’s regional headquarters located in Bangalore and expanded its operations with other branches located in various places, like Ahmedabad, Bhubaneshwar, Chennai, Coimbatore, Delhi, Gurgaon, Hyderabad, Kochi, Kolkata, Mumbai, Noida, Pune, Mysore and Visakhapatnam.

IBM Interview Questions

In 2020, IBM achieved a remarkable feat by securing the highest annual U.S. patents for 28 consecutive years, solidifying its position as a prominent research institution. IBM, commonly called Big Blue, is one of the 30 corporations listed in the Dow Jones Industrial Average and ranks among the world’s largest employers, with approximately 345,000 employees as of 2020. A fundamental element of IBM’s culture, which has significantly contributed to its enduring success, is its capacity to accept and actively promote innovative concepts. This blog will explore IBM interview questions to equip Freshers jobs seekers.

Job Seekers can apply for new job vacancies through Freshers Jobs in Bangalore.

Interview Process

Candidates should generally clear 4 levels of the interview process to be hired at IBM. These 4 levels are conducted to test the candidate’s technical knowledge and analytical abilities.

  • Cognitive Ability Assessment
  • Coding Round
  • Technical Interview
  • HR Interview

Each of these levels consists of eliminations. So, candidates must crack all these levels in the IBM interview process to be selected.

Interview Rounds

  • Cognitive Ability Assessment: The first level of the interview process is Cognitive Ability Assessment. It is conducted to assess the candidate’s cognitive ability. This level consists of specific amusing games, like Shortcuts, Resembles, Numbubbles, and Tally Up. This round may be conducted in WerEx, and a proctor will watch the candidates while they are playing. Results for this round will be quickly processed within half an hour. Candidates selected in this round will receive links for the next round.
  • Coding Round: The next level in the IBM interview process is Coding Round. It is a dynamic field, ranging from 1 to 4 coding questions. The duration given to solve them will differ according to the number of questions to be solved. Usually, 1 to 2 questions will be 30 to 45 minutes. If the questions to be solved are 3 to 4, then the time allotted will be 1 – 2 hours. This round generally assesses the candidate’s coding skills and their knowledge of various algorithms and data structures. The candidates can code in any modern programming language like C, C++, Java, and Python. The candidates should prepare data structures, algorithms and various types of coding questions related to it.
  • Technical Interview: The third level in the IBM recruitment process is the Technical Interview Round. Candidates who have cleared the online assessment will be selected for the Technical Interview Round in person. Technical Interviews are conducted to assess a candidate’s technical skills, which vary depending on the job role you are applying for. Apart from technical skills, it will also help you develop and assess your critical thinking and problem-solving skills and how to handle a stressful situation. Questions related to your final year projects will also be asked. Candidates should be well prepared with the fundamental concepts of Computer Science. Proficiency in modern programming languages, like C, C++, Java, and Python, is mandatory for a candidate to crack this round. The question most commonly encountered in this round pertains to OOP (Object-Oriented Programming Systems), DBMS (DataBase Management System), Computer Networks (CN), Computer Organization and Architecture (CoA), and Operating Systems (OS). The number of technical interviews will be based on your previous round’s performance, job profile, and the company’s demand. Generally, each candidate will be attending 2 rounds of technical interviews.
  • HR Round: After clearing the Technical round, the candidates will be invited for the HR round. This level is the final level in the IBM recruitment process. The primary objective of an HR interview is to evaluate a candidate’s personality, background, strengths, and weaknesses to determine their suitability for a specific role. Therefore, it is crucial to be well-prepared for the HR interview. Before the interview, review your resume to ensure that all relevant personal information is included and that the provided data is as accurate as possible. Additionally, be ready to respond to questions related to IBM’s history, such as its founding date, goals, principles, and organizational structure. Anticipate and be prepared to address any inquiries about your resume, and in your responses, articulate your passion for the profession and what drives you the most.

Click IBM Jobs for freshers to navigate through new job openings.

HR Interview Questions

Given below are the IBM interview questions for HR round.

  1. Could you tell us about yourself?

Start your answer by explaining details like educational qualifications, skills, interests, goals, hobbies, passion for the job, etc. The answer should be short and must consist of all the required information.

  1. Are you open to relocating to different regions within India?

Tell them whether you are open to relocating to different regions within India. If yes, tell how that flexibility benefits your professional and personal growth.

  1. What drives your interest in joining IBM?

Tell them about what aspect of the specific company attracted you the most. Ensure that you make good use of the information that you have obtained by researching the company.

  1. Where do you envision yourself five years from now?

Tell them what your expectations are for yourself after 5 years. Tell them about your career growth expectation after 5 years from the present.

  1. Share details about your internships and projects.

This question is an opportunity to showcase your understanding of your final year project and the insights you gained from your internship program.

  1. Suppose you’re leading a team; one member consistently underperforms despite multiple warnings. How would you handle this situation?

Sample answer: “If I were leading a team as a fresher and encountered a situation where one team member consistently underperforms despite multiple warnings, I would approach it by first trying to understand the root cause of their underperformance. I would have a one-on-one conversation with the team members to discuss their challenges and concerns and provide them with constructive feedback. I would also offer my assistance and support to help them improve. If, after several attempts to help them, the underperformance continues and negatively affects the team’s progress, I would involve my superiors or the HR department to explore further solutions. Maintaining clear communication and documentation of the performance issues and efforts to address them throughout the process is essential. Ultimately, my goal would be to find a balanced approach that supports the team member’s development while ensuring that the team’s overall performance is not compromised”.

Technical Interview Questions

Given below are the IBM interview questions for the Technical interview.

  1. What is the function of the sudo command in the UNIX operating system?

sudo stands for Super Users DO. In Unix, the sudo command is a prefix to a command that can only be run by superusers. Suppose the prefix “sudo” is used before a command. In that case, that command will be run with elevated privileges by allowing a user with all the required permissions to run a command as another user, like a superuser. This command represents the Windows edition of the “run with administrator privileges” feature. In the “/etc/sudoers” file, there should be an entry for every user authorized to utilize the sudo command. When modifying or reviewing the sudoers file, it is advisable to employ the sudo command. For editing the sudoers file, it is recommended to use the “visudo” command.

  1. What is virtual memory in the operating systems?

Generally, Virtual is a storage allocation system that permits secondary memory to be addressed as the main memory. Application addresses for referencing memory differ from the addresses the memory system employs to identify physical storage locations and program-generated addresses are automatically converted into machine addresses.

The computer system’s addressing approach constrains the virtual storage capacity, and the quantity of secondary memory accessible is determined by the number of primary storage slots available, not the actual count of primary storage positions.

  1. What is an Entry controlled loop in OOP programming?

If the condition is true, an entry control loop supervises the condition at the point of entry and transfers control to the loop’s body. The term “entry control loop” is derived from its function of controlling the entry into the loop.

Given below are the IBM interview questions in detailed format.

  1. Describe the fundamental principles of Object-Oriented Programming in C++.

There are 4 fundamental principles of Object-Oriented Programming.

Encapsulation: In Object-Oriented Programming, Encapsulation involves bundling data and the functions that manipulate it within a class. This principle shields a class’s variables or data from external classes and restricts access to them through member functions.

For instance, consider a company with various departments like accounts, finance, and sales. The finance department is responsible for financial data, while the sales department manages sales-related information. If someone from finance needs sales data, they must request it from a sales department official. Requesting data from the sales department represents encapsulation, where data and its authorized access are grouped under the “sales section.”

Abstraction: Abstraction only reveals the essential information while hiding the implementation details. Data abstraction involves exposing the critical aspects of data to the outside world while concealing the intricacies of managing data.

For instance, think of a person driving a car; they know that pressing the accelerator increases speed and using the brakes stops the vehicle, but they don’t need to understand the inner workings of the car’s engine or control mechanisms. This approach illustrates abstraction.

Inheritance: Inheritance refers to a class’s ability to inherit attributes and behaviors from another class. In Object-Oriented Programming, this is a fundamental concept. A class that inherits properties is called a derived class, while the class whose properties are inherited is the base class. Inheritance promotes “reusability.”

Consider a class like “Vehicle” that contains essential vehicle functions. Classes like “Car,” “Bus,” and “Truck” can all be considered subclasses of “Vehicle” because they need to have these essential vehicle properties.

Polymorphism: Polymorphism is the concept of something having multiple forms. It’s the ability for a message to be represented in various ways.

For instance, a person can have different roles, like being a parent, a spouse, and an employee, and they may behave differently in these roles.

In C++, there are two primary types of polymorphism:

  • Compile Time Polymorphism: Achieved through function overloading and operator overloading.
  • Runtime Polymorphism: Created by function overriding.
  1. Explain the 3 types of schedulers in operating systems.

Schedulers are specialized computer programs that manage process scheduling in various ways. Their primary responsibility is to select the right jobs to submit into the system and which process to run.

Given below are the 3 types of schedulers.

  • Long-Term Scheduler: Often called a job scheduler, the long-term scheduler selects which programs are admitted into the system for processing. It picks processes from the ready queue and loads them into memory for execution. In the context of CPU scheduling, the process is loaded into memory. The primary objective of the job scheduler is to provide a well-balanced mix of jobs, including I/O-bound and CPU-bound workloads. It also controls the level of multiprogramming. If the level of multiprogramming remains constant, the average rate of process creation must match the average rate of process departure from the system.
  • Medium-Term Scheduler: Medium-term schedulers are utilized to swap processes in and out of main memory, freeing up memory previously occupied by processes. This action reduces the degree of multiprogramming. The medium-term scheduler manages the processes that have been swapped out.
  • Short-Term Scheduler: Also known as a CPU scheduler, the short-term scheduler’s primary aim is to enhance system performance based on established criteria. It facilitates the transition of a process from the ready state to the running state. The CPU scheduler selects a process from the pool of ready processes and assigns the CPU to that chosen process. Short-term schedulers, often referred to as dispatchers, make decisions about which process to run next.
  1. Explain the functions of an Operating System.

Below mentioned are the functions of the OS.

Provides User Interface: OS provides an interface between the users and computer hardware. Through this interface, users can systematically access the hardware.

Maintenance of the System’s performance: It enhances the performance by supervising the overall system. It is essential to keep track of the time between the service requests and system responses to obtain a proper structure of the system’s performance. This approach can improve the performance by providing critical information for troubleshooting problems.

Security: The operating system uses password protection and similar security measures to secure user data. It also secures applications and user data from illegal or unauthorized access.

Error-detection: The OS constantly supervises the system to detect errors and prevent the computer system from system failure.

Memory Management: The main memory contains an extensive array of bytes or words, each allocated an address. The CPU can access the main memory directly since it is a rapid storage. Before executing a program, it must be loaded into the main memory. Given below are the tasks performed for memory management.

  • It maintains a record of the allocation and utilization of memory addresses in primary memory, identifying which memory locations are currently used by user programs and which remain unallocated.
  • In a multiprogramming environment, the operating system governs the sequence in which processes are granted memory access and the duration for which they can use it. It grants memory to a process upon request and releases memory when it terminates or engages in I/O operations.

Processor Management: The operating system oversees the order in which tasks gain access to the processor and the allocation of processing time for each process.

Device Management: An operating system (OS) manages device connectivity through drivers and maintains a record of all connected devices. The Input/Output controller, a program responsible for all devices, determines the permissions and time allocation for processes to access a device, striving for effective and efficient device allocation. Devices are deallocated when they are no longer needed.

File Management: The file system is organized into directories to enhance navigation and efficiency. These directories contain various files and subdirectories, with the operating system tracking the location of data, user access permissions, and the status of each file, among other attributes.

  1. Explain the Database Management System. State its merits over traditional file systems.

Database management system (DBMS) is a small piece of software that handles database management. Some examples of database management systems are MySQL, Oracle, and other commercial databases. A DBMS (Database Management System) gives an interface for performing tasks like constructing a database, storing data in it, data updation, and table creation in a database, among others. It keeps track of the safety and security of a database. In the case of multiple users, it also oversees the data consistency.

Given below are the merits of DBMS (Database Management System) over traditional file systems:

  • Better Data Management: The users can access better-managed data through a database management system. This aspect enables the end users to check their data and respond quickly if any changes are required.
  • Improved Data Security: As thequantity of users rises,the data transfer rate also rises. It results in more requirements for data security due to the rise of cyber crimes. Data security is expected in the corporate world. Organizations spend money and time and put a lot of effort into securing their data from unauthorized access. A Database management system (DBMS) helps the organization by providing a better platform for data security and privacy regulations and improving data security.
  • Reduction of Data inconsistency: During the interruption of various versions of similar data in various places, data consistency is reduced in the Database management system. For instance, a student’s name is stored as “R. Raghul” on the school’s main computer, while the same student’s name is stored as “Raghul Raghavan” on the teacher’s registered system.
  • Faster data access: A database management system improves the speed of the responses to the database queries by enabling fast and more accurate data access. As a result, end users will have better data access while working with a large amount of sales data, increasing the sales cycle’s speed.
  1. Explain ACID properties of transactions in the Database Management System.

In an SQL Database, each transaction should follow a specific set of properties. These properties are called ACID properties.

Atomicity: This property implies that a transaction either happens entirely or not at all, with no intermediate stages. Transactions are treated as indivisible units that are either fully executed or aborted. This property involves the following two steps.

  • Abort: If a transaction is aborted, the modifications made will be lost.
  • Commit: If a transaction is committed, its changes will be visible.

For instance, take a bank transaction transferring funds from one account to another. This transaction must either be executed in whole or fail altogether. There is no possibility of an intermediate state where money is debited from one account but has yet to be credited to the other.

Consistency: This principle dictates that integrity constraints must be followed before and after a transaction to maintain the database’s consistency and correctness.

For instance, in a bank transaction transferring funds from account A with balance X to account B with balance Y, the total amount of money must remain constant (X + Y) after the transaction is completed.

Isolation: This characteristic guarantees that multiple transactions can occur concurrently without introducing database state inconsistencies. Transactions proceed without interfering with one another, and modifications made in one transaction are not visible to other transactions until that transaction’s updates are written to memory or committed. This feature ensures that the concurrent execution of transactions results in a state identical to what would be achieved if they were executed sequentially in some order.

For instance, in a country, a bank operates numerous ATMs, all of which can function simultaneously, as if each were the sole transaction being processed on the bank’s database, thus ensuring isolation.

Durability: The durability attribute ensures that once a transaction has completed its execution, the database updates and modifications are saved and written to non-volatile memory, making them permanent and resilient to system failures. Consequently, the effects of the transaction are always recovered.

For instance, it is essential to maintain a backup database so that in case the primary database fails, data can be recovered from the backup database.

  1. Explain Arrays and their real-life applications.

An array is a grouping of items stored in a memory location. Its fundamental role is to bring together items of the same type. Arrays simplify the process of determining the position of each element by adding an offset to a base value, like the memory address of the array’s initial element.

Given below are the real-life applications of an array.

  • One of the purposes of the array is to store the data in a simple application in a tabular format. For instance, if you want to store contacts on your mobile, the software will generate an array with all your contacts.
  • Another application of arrays is to organize a game’s leaderboard to keep track of the score and arrange them in descending order to see the rank of the players.
  • A direct question paper will contain numbered questions, each assigned with a set of marks.
  • 2D arrays or matrices are often used in image processing.
  • The array is also used in speech recognition to represent each spoken signal.
  1. Explain the Deadlock and its conditions in the Operating System.

A deadlock occurs when a group of processes are stopped or halted because each process holds a resource and waits for another process to obtain it.

Let’s assume a situation where 2 trains are fast approaching each other on the same track. Once both the trains approach each other, neither of them can move. Similarly, in the operating system, there will be a situation where several processes hold specific amounts of resources while waiting on resources held by other processes.

For instance, let’s consider that 2 trucks are trying to cross each other on a one-way bridge. Neither truck is ready to move back in this situation, so neither can cross the bridge. In a situation like this, a deadlock has been obtained.

Given below are the necessary conditions for deadlocks.

  • Mutual Exclusion: In this condition, specific resources are not designed for sharing; thus, only a single process can utilize a resource at any given time.
  • Hold and Wait: This situation arises when a process currently possesses at least one resource and waits for additional resources to be allocated.
  • No Preemption: Under this circumstance, resources can only be acquired by a process if that process voluntarily releases them. In other words, there should be no forced seizure of resources.
  • Circular Wait: This condition refers to a scenario in which a set of processes are waiting for each other circularly or cyclically, creating a deadlock situation.

IBM interview questions given below state the differences between the 2 topics.

  1. State the differences between primary memory and secondary memory in computers.
  • Primary/Main Memory: A computer memory that the CPU can directly access is known as primary memory. It is built by Dynamic Random Access Memory (DRAM) and facilitates the processor with an actual working space. It oversees the data and instructions that the processor processes.

E.g., RAM (Random Access Memory)

  • Secondary Memory: As the processor lacks direct access to secondary memory, the contents of secondary memory must be initially transferred to primary memory before the processor can access them.

E.g., Hard disks and USB drives

Given below are the differences between Primary Memory and Secondary Memory.

Primary Memory Secondary Memory
Primary memory provides temporary storage. Secondary memory offers permanent storage.
The processor/CPU enjoys immediate access to primary memory. The processor/CPU lacks immediate access to primary memory.
Primary memory can be volatile (requiring power to maintain stored information) or non-volatile. Secondary memory is consistently non-volatile (needing no power to maintain stored data).
Primary memory relies on semiconductor memories for its functionality. Secondary memory utilizes magnetic and optical memories as its storage devices.
Primary memory is generally more costly than secondary memory. Secondary memory devices, when compared to primary memory devices, tend to be more budget-friendly.
  1. Explain processes and threads in the operating system.
  • Process: If a program is executed, it is known as a process. A process control block controls a process. The other information regarding the process, like Process priority, process id, process state, CPU, register, etc, are stored in the Process control block (PCB). Child Processes are generated when a process gives rise to another process. They have an extended lifespan and are segregated, meaning they do not share memory with other processes.
  • Thread: A thread is known as a section of a process, which can have numerous threads. Thread can be in any of these 3 states: running, ready, or blocked. Threads consume less time for termination when compared to processes. But they don’t isolate like processes.

Given below are the differences between Process and Thread.

Process Thread
Creating a process requires more time. Creating a thread is a quicker operation.
Context switching from one process to another is time-consuming. Context switching between threads within the same process is more efficient.
In terms of intercommunication, processes could be more efficient. Threads offer better intercommunication efficiency.
Processes have their separate memory areas and do not share memory. Threads within the same process share memory.
Each process has its unique Process Control Block, Stack, and Address Space. Threads within the same process share the Process Control Block but have individual Thread Control Blocks, stacks, and address spaces.
When a process gets blocked, it doesn’t impact other running processes. When a thread gets blocked, it affects all other threads within the same process.
Process switching utilizes the operating system interface. Thread switching does not require invoking the operating system or causing a kernel interrupt.
  1. State the differences between struct and union in the C programming language.
  • struct: It is a user-defined data type that enables the user to combine data objects of different types. A structure emphasizes a record.

The syntax of struct is as follows,

struct structureName {

member definition,

member definition,

/* … */

member definition


  • union: A unique data type enables users to store several data types in the same memory region. A union can hold several members, but only one can hold a value at a given time. Unions are an approach that enables the reuse of the same memory space for several purposes.

The syntax for union is as follows,

union unionName {

member definition,

member definition,

/* … */

member definition


Given below are the differences between struct and union.

struct union
A struct is declared using the “struct” keyword. A union is declared using the “union” keyword.
When variables are declared in a struct, the compiler allocates memory for each member variable, and the size of the struct is determined by the total size of its data members. In a union, memory is allocated for the member variable with the largest size, and the most extensive data member’s size determines the union’s size.
Changing the value of a variable in a struct does not affect other variables within the struct. Changing the value of one variable member in a union can affect the values of other variable members within the same union.
Each member variable in a struct has its own separate memory space. In a union, all variable members share the same memory space allocated to the variable with the largest size.
Multiple variables within a struct can be initialized simultaneously. In a union, only the first data member can be initialized.
In a struct, all variable members can hold values at any point in the program. In a union, at any given point in the program, only one data member can hold a value.
Structs are used to manage values of various data types. Unions store one value at a time from various data types.
Structs allow for simultaneous access and retrieval of any data member. Unions allow you to access and retrieve individual data members one at a time.
  1. State the differences between variable or function declaration and definition in any OOP programming language.

The purpose of declaring variables is to give the compiler specific information about the variable. The information includes the variable’s name, the type of value stored, and the initial value (if any). Simply put, a declaration provides information about the variable’s attributes. The variable definition will allocate the variable’s memory space and determine where it will be stored.

Given below are the differences between Definition and Declaration.

Definition Declaration
A variable can only be defined once. No restriction exists on how many times a variable or function can be declared.
Memory is allocated at the time of definition. Memory is not allocated during declaration.
For example, consider the code:

void fun() {

cout << “Hello World” << “\n”;


The code above defines a void function called “fun,” the compiler allocates memory for it when it encounters this code.

For example, consider the code:

void fun();

This code declares a void function named “fun.”

  1. Differentiate between quick and merge sort in the Sorting Algorithm.
Quick Sort Merge Sort
Quick Sort partitions the array into arbitrary segments without equal division. Merge Sort divides the array into 2 halves (i.e., n/2).
The worst-case time complexity of Quick Sort is O(n^2). In Merge Sort, the worst-case and average-case time complexities are O(n log n).
Quick Sort could be better suited for handling extensive datasets. Merge Sort is suitable for sorting datasets of any size, whether large or small.
Quick Sort is a sorting algorithm that operates in place without extra storage. Merge Sort is not an in-place sorting algorithm; it requires extra memory space for auxiliary arrays.
Quick Sort can be unstable, but it can be made stable with some code adjustments. Merge Sort is a stable sorting algorithm preserving the relative order of elements with the same.
Quick Sort is a preferable choice for sorting arrays. Merge Sort is a preferred choice for sorting linked lists.
Quick Sort exhibits good cache locality, often resulting in faster performance than Merge Sort, especially in virtual memory environments. Merge Sort needs to exhibit a better locality of reference.
  1. What is Procedural Programming? State the differences between object-oriented programming.

Procedural programming is a programming model that emerged from structured programming, and it is based on the invoking procedures’ concepts. Procedures or routines/ subroutines/ functions are a set of instructions that have to be executed. It is possible to invoke any program during execution using the program itself or other procedures.

Given below are the differences between Procedural and Object-oriented programming.

Procedural Programming Object-Oriented Programming
Procedural programming involves breaking the program into small modules referred to as functions. Object-oriented programming dissects a program into distinct components known as objects.
The top-down approach is applied in procedural programming. Object-oriented programming adopts a bottom-up methodology.
Incorporating new data and functions takes a lot of work. Adding extra data and functions is a straightforward task in object-oriented programming.
Procedural programming does not support method overloading. Method overloading is a viable feature in object-oriented programming.
Due to the absence of a proper data-hiding mechanism, procedural programming is considered less secure. Object-oriented programming ensures the concealment of data, enhancing security.
In procedural programming, functions hold more prominence than data. In object-oriented programming, data holds greater significance than functions.
Examples of programming languages for procedural programming include C, FORTRAN, Pascal, Basic, and others. Programming languages like C++, Java, Python, C#, and others serve as examples of object-oriented programming.

Given below are coding-based IBM interview questions.

  1. In a sorted array consisting of only 0s and 1s, the objective is to find the index of the first occurrence of ‘1.’ If the array contains no ‘1’s, the result should be “-1.”



arr = {2, 2, 2, 3, 3, 4, 4, 4, 4}




arr = {0, 1, 1, 1, 1, 1} 



Approach: Utilizing the inherent sorted property of the array, we employ a binary search approach to locate the first occurrence of ‘1’ within the given array. Our initial search space encompasses the entire array, and we pinpoint the middle element. If the middle element is ‘0’, it signifies that the solution exists to the right of this middle element. If the middle element is ‘1’, our answer can either be the current index or any indices to the left of the current middle, provided there are more ‘1’s preceding it.


def max_consecutive_occurrences(arr):

if not arr:

return 0

max_count = 1

current_count = 1

for i in range(1, len(arr)):

if arr[i] == arr[i – 1]:

current_count += 1


current_count = 1

if current_count > max_count:

max_count = current_count

return max_count

# Test cases

arr1 = [2, 2, 2, 3, 3, 4, 4, 4, 4]

arr2 = [0, 1, 1, 1, 1, 1]

print(max_consecutive_occurrences(arr1)) # Output: 4

print(max_consecutive_occurrences(arr2)) # Output: 1

Output 1:

First occurrence of 1 in the first input: 4

Output 2:

First occurrence of 1 in the second input: 1

  1. Create a program that transforms the case of characters in a string, such that lowercase characters become uppercase and vice versa.









Approach: The method includes iterating through each character within the string. When the current character is in lowercase, it is transformed into uppercase by subtracting 32 from its ASCII value. Conversely, if the current character is in uppercase, it is transformed into lowercase by adding 32 to its ASCII value.


#include <iostream>

using namespace std;

void changeCase(string& s) {

for (char& c : s) {

if (islower(c)) {

c = toupper(c); // Convert lowercase to uppercase

} else if (isupper(c)) {

c = tolower(c); // Convert uppercase to lowercase




int main() {

string input1 = “SaMpLeINpUt”;

cout << “Original String 1: ” << input1 << “\n”;


cout << “Changed String 1: ” << input1 << “\n”;

string input2 = “ThisIsAnExample”;

cout << “Original String 2: ” << input2 << “\n”;


cout << “Changed String 2: ” << input2 << “\n”;

return 0;


Output 1:

Original String 1: SaMpLeINpUt

Changed String 1: sAmPlEinPuT

Output 2:

Original String 2: ThisIsAnExample

Changed String 2: tHISiSaNeXAMPLE

  1. Create a program that determines the number of possible ways to change for a total of N cents when an unlimited quantity of different-valued coins (C1, C2, … Cm) is available. The order in which the coins are used does not affect the outcome.


N = 5, C = {1, 2, 3} 




N = 8, C = {2, 3, 4} 



Approach: We can categorize all possible solutions into two groups for calculating the total number of ways:

  • Solutions that don’t include the mth coin (Cm).
  • Solutions that include at least one Cm.

If we denote the function for counting the number of solutions as solve(C[], m, n), it can be expressed as the sum of solve(C[], m-1, n) and (C[], m, n-Cm). To optimize our time complexity, we’ll employ dynamic programming to store the results for specific values of n and m. This approach will achieve a time complexity of O(nm).


#include <bits/stdc++.h>

using namespace std;

int countWays(int coins[], int m, int n) {

int dp[n + 1] = {0};

dp[0] = 1;

for (int i = 0; i < m; i++) {

for (int j = coins[i]; j <= n; j++) {

dp[j] += dp[j – coins[i]];



return dp[n];


int main() {

int coins1[] = {1, 2, 3};

int m1 = sizeof(coins1) / sizeof(coins1[0]);

int n1 = 5;

cout << countWays(coins1, m1, n1) << endl;

int coins2[] = {2, 3, 4};

int m2 = sizeof(coins2) / sizeof(coins2[0]);

int n2 = 8;

cout << countWays(coins2, m2, n2) << endl;

return 0;


Output 1:


Output 2:


  1. Describe function overloading and overriding in C ++ programming language. State the differences between them.
  • Function Overloading: It permits the creation of various function definitions by altering the function’s signature, including the number of parameters, the data types of the parameters, and the return type.

Sample coding:

#include <iostream>

using namespace std;

// Method 1

void overloadedMethod(int x)


cout << “In Overloaded Method 1” << endl;


// Method 2

void overloadedMethod(float x)


cout << “In Overloaded Method 2” << endl;


// Method 3

void overloadedMethod(int x1, float x2)


cout << “In Overloaded Method 3” << endl;


int main()


int x = 5;

float y = 5.5;



overloadedMethod(x, y);

return 0;



In Overloaded Method 1

In Overloaded Method 2

In Overloaded Method 3

  • Function Overriding: Function overriding is redefining a function from a base class within a derived class, maintaining the same function signature, which includes both the return type and the parameters. This practice is exclusive to derived classes.

Sample Coding:

#include <iostream>

using namespace std;

class Test {


virtual void print() {

cout << “Test Function”;



class Sample : public Test {


void print() {

cout << “In Sample Function”;



int main() {

Test* obj = new Sample(); // Use a pointer to the base class.

obj->print(); // Use -> to call the virtual function.

delete obj; //Don’t forget to delete dynamically allocated objects.

return 0;



In Sample Function

Below are the differences between Function overloading and overriding.

  • In the context of class inheritance in C++, it leads to overriding functions, while overloading typically occurs within the same class.
  • Overloaded functions within a class must possess distinct function signatures, implying that they must differ in the number or type of parameters. In contrast, when overriding functions in a derived class, it is essential to maintain identical function signatures as those in the base class.
  • Moreover, overloaded functions coexist within the similar scope of a class, meaning they are defined within the class. On the other hand, overridden functions are found in different scopes: the base class and the derived class, as they are separate classes participating in inheritance.

In conclusion, preparing for an IBM interview requires a multifaceted approach. It would help if you had a solid understanding of the technical aspects relevant to the role you’re applying for, whether in software development, data science, cloud computing, or any other domain. It is equally important to master behavioral and situational questions and demonstrate your problem-solving abilities, adaptability, and teamwork skills. Remember, an IBM interview isn’t just about proving your technical competence and showcasing your potential to contribute to a continuous learning and innovation culture. We have covered a wide range of IBM interview questions in this blog.

Leave a Reply

Your email address will not be published. Required fields are marked *