Table of contents
1.
Introduction
2.
Beginner Level IBM Interview Questions and Answers
2.1.
1. What is agile methodology?
2.2.
2. What is virtual memory?
2.3.
3. What is DNS & how does it work?
2.4.
4. Explain the ACID properties in database systems.
2.5.
5. Explain the concept of recursion.
2.6.
6. Define the principles of object-oriented programming
2.7.
7. Describe OSI model layers.
2.8.
8. What is an IP address & its types?
2.9.
9. Explain the difference between multitasking & multithreading.
2.10.
10. Describe the basic principles of cloud computing.
3.
Intermediate Level IBM Interview Questions and Answers
3.1.
11. Explain the difference between abstraction & encapsulation. 
3.2.
12. Describe the functioning of a Content Delivery Network (CDN).
3.3.
13. What is Docker & how is it used in software development?
3.4.
14. Explain the concept of microservices architecture.
3.5.
15. How does ARP work? Describe ARP spoofing.
3.6.
16. What is Git & how does it facilitate version control?
3.7.
17. Describe design patterns, its types and examples.
3.8.
18. Explain process synchronization & its methods.
3.9.
19. Describe the boot process of a typical operating system.
3.10.
20. Explain the concept of VLANs & its advantages.
4.
Advanced Level IBM Interview Questions and Answers
4.1.
21. What is a deadlock? How can it be prevented?
4.2.
22. What are the advantages & disadvantages of using RESTful APIs?
4.3.
23. How does SSL/TLS ensure secure communication over the internet?
4.4.
24. Explain Big-O notation & its significance in algorithms.
4.5.
25. Explain the concept of paging & its benefits.
4.6.
26. Implement a function to merge two sorted linked lists.
4.7.
27. Explain process synchronization & its methods.
4.8.
28. Implement a queue using two stacks.
4.9.
29. What is the difference between kernel-level threads & user-level threads?
4.10.
30. Write a program to find the maximum subarray sum.
5.
Conclusion
Last Updated: Jul 2, 2024
Medium

IBM Interview Questions

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

IBM is one of the world's largest technology companies, known for its computer hardware, middleware, software, and IT consulting services. Many people dream to work at IBM after graduation, but to land a job there, they need to perform well in the IBM interview. 

IBM Interview Questions

This article will answer some common questions asked in IBM interviews, explaining topics such as agile methodology, virtual memory, DNS, databases, programming, and more. 

Beginner Level IBM Interview Questions and Answers

1. What is agile methodology?

Agile is a project management approach that breaks large projects into smaller, manageable chunks called sprints. The team works on these sprints one at a time, regularly checking progress and adapting plans as needed. Agile focuses on collaboration and quick changes, allowing teams to respond to shifting requirements and deliver value faster. Two popular agile frameworks are Scrum and Kanban, each with its own set of practices and ceremonies.

2. What is virtual memory?

Virtual memory is a memory management technique that allows programs to use more memory than is physically available on the computer. Parts of the program's memory that are not currently in use are stored on the disk, while active parts are loaded into physical RAM. The operating system and the CPU's memory management unit work together to manage virtual memory, providing memory protection between programs and ensuring smooth operation.

3. What is DNS & how does it work?

DNS, or Domain Name System, is responsible for translating human-readable domain names (like www.example.com) into machine-readable IP addresses. When you type a URL into your browser, DNS works behind the scenes to find the matching IP address. It does this by querying a distributed database of name-to-IP mappings, with DNS servers recursively searching until the correct IP is found. Results are then cached to speed up future lookups.

4. Explain the ACID properties in database systems.

ACID is an acronym that stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure the reliability of database transactions. Atomicity means that transactions are all-or-nothing – either they fully complete, or they fail and leave the database unchanged. Consistency ensures that transactions take the database from one valid state to the next, without introducing any inconsistencies. Isolation guarantees that concurrent transactions don't interfere with each other, acting as if they were executed sequentially. Durability ensures that once a transaction is committed, its changes are permanent and will survive any subsequent system failures.

5. Explain the concept of recursion.

Recursion is a programming technique where a function calls itself to solve a problem. Recursive functions have a base case that ends the recursion, and each recursive call works on a smaller subproblem. The results from these subproblems are then combined to solve the overall problem. Recursion is an alternative to iteration (loops) and is often used for problems that have a naturally recursive structure, such as calculating factorials, generating Fibonacci sequences, or traversing trees and graphs.

Here's an example of a recursive function in C that calculates the factorial of a number:

int factorial(int n) {
  if (n == 0) { // base case
    return 1;
  } else {
    return n * factorial(n-1); // recursive case
  }
}
You can also try this code with Online C Compiler
Run Code

 

6. Define the principles of object-oriented programming

Object-oriented programming (OOP) is based on four main principles:

  • Encapsulation: This involves bundling data and methods into objects and hiding the internal details of the object from the outside world. Encapsulation helps to protect the data and ensures that it can only be accessed or modified through well-defined interfaces.
  • Abstraction: Abstraction means exposing only the essential features of an object and hiding the complexity behind a simple interface. This allows programmers to focus on using the object without worrying about its internal workings.
  • Inheritance: Inheritance is a mechanism that allows new objects to be based on existing objects, inheriting their properties and behaviors. This promotes code reuse and helps to organize objects into hierarchies.
  • Polymorphism: Polymorphism means that objects can take many forms and respond to the same interface in different ways. This allows for flexibility and extensibility in object-oriented designs.

7. Describe OSI model layers.

The Open Systems Interconnection (OSI) model is a conceptual framework that describes the functions of a networking system. It consists of seven layers, each with a specific role:

  1. Physical layer: This layer is responsible for transmitting raw bit streams over a physical medium, such as ethernet cables or wifi.
  2. Data Link layer: The data link layer transfers data between nodes on a network, handling tasks such as physical addressing and error detection.
  3. Network layer: This layer is responsible for routing data packets between different networks, using logical addresses (IP addresses).
  4. Transport layer: The transport layer provides end-to-end data delivery and error recovery services, ensuring that data is delivered reliably between applications.
  5. Session layer: This layer establishes, manages, and terminates connections between applications, allowing them to communicate with each other.
  6. Presentation layer: The presentation layer is responsible for converting data between the formats used by the network and the application, handling tasks such as encryption and compression.
  7. Application layer: This is the topmost layer, providing network services directly to the applications, such as email, file transfer, and web browsing.

8. What is an IP address & its types?

An IP (Internet Protocol) address is a unique identifier assigned to each device on a network. There are two main types of IP addresses:

  1. IPv4 addresses are 32-bit addresses written in dotted decimal notation, like 192.168.1.1. They are the most common type of IP address, but due to the limited number of available addresses, they are gradually being replaced by IPv6.
  2. IPv6 addresses are 128-bit addresses written in hexadecimal notation, like 2001:0db8:85a3:0000:0000:8a2e:0370:7334. They provide a much larger address space and are designed to replace IPv4 addresses.

9. Explain the difference between multitasking & multithreading.

Multitasking and multithreading are both ways of achieving concurrency in a system, but they operate at different levels.

Multitasking refers to the ability of an operating system to run multiple processes simultaneously. Each process has its own memory space and resources, and the operating system switches between them to give the illusion of simultaneous execution. Context switching between processes is relatively expensive, as the entire state of the process must be saved and restored.

On the other hand, multithreading refers to the ability of a single process to have multiple threads of execution running concurrently. Threads within a process share the same memory space and resources, making context switching between threads much cheaper than between processes. However, this also means that thread failures can potentially bring down the entire process.

10. Describe the basic principles of cloud computing.

Cloud computing is based on several key principles:

  1. On-demand self-service: Users can provision computing resources, such as servers and storage, as needed without requiring human interaction with the service provider.
  2. Broad network access: Cloud services are available over the network and can be accessed using standard mechanisms from a variety of devices, such as laptops, tablets, and smartphones.
  3. Resource pooling: The provider's computing resources are pooled to serve multiple consumers, with different physical and virtual resources dynamically assigned and reassigned according to consumer demand.
  4. Rapid elasticity: Capabilities can be rapidly and elastically provisioned, in some cases automatically, to quickly scale out and scale in based on demand. To the consumer, the capabilities available often appear to be unlimited.
  5. Measured service: Cloud systems automatically control and optimize resource use by leveraging a metering capability. Resource usage can be monitored, controlled, and reported, providing transparency for both the provider and consumer of the utilized service.

Intermediate Level IBM Interview Questions and Answers

11. Explain the difference between abstraction & encapsulation. 

Abstraction & encapsulation are two fundamental concepts in object-oriented programming, but they serve different purposes.

Parameters

Abstraction

Encapsulation

PurposeHiding complexityHiding internal details
FocusWhat an object doesHow an object does it
Achieved throughAbstract classes, interfacesAccess modifiers
AccessibilityDefines behaviorControls access

 

12. Describe the functioning of a Content Delivery Network (CDN).

A Content Delivery Network (CDN) is a geographically distributed network of servers that work together to provide fast delivery of internet content. 

Here's how it works:

  1. A user requests content (e.g., a website, video, image) from a website.
  2. The request is routed to the nearest CDN server (also called an edge server).
  3. If the content is already cached on the edge server, it's delivered to the user.
  4. If not, the edge server requests the content from the origin server, caches it, & then delivers it to the user.

 

By serving content from a server close to the user, CDNs reduce latency, improve load times, & reduce the load on the origin server. They're commonly used to deliver static content like images, videos, & CSS/JavaScript files.

13. What is Docker & how is it used in software development?

Docker is a platform for developing, shipping, & running applications using containers. A container is a lightweight, standalone executable package that includes everything needed to run a piece of software, including the code, runtime, system tools, libraries, & settings.

In software development, Docker is used to:

  1. Ensure consistency across environments (dev, test, prod) by packaging the app & its dependencies into a container.
  2. Simplify application deployment by providing a standardized unit of deployment (the container).
  3. Improve efficiency by allowing multiple containers to run on the same machine, sharing the OS kernel.
  4. Facilitate microservices architecture by providing a way to package & deploy individual services as containers.

14. Explain the concept of microservices architecture.

Microservices architecture is a way of structuring an application as a collection of small, independent services. Each service runs in its own process & communicates with other services through lightweight mechanisms, often an HTTP API.

Important characteristics of microservices architecture are:

  1. Services are small, focusing on doing one thing well.
  2. Services are independently deployable & scalable.
  3. Services are organized around business capabilities.
  4. Services communicate via well-defined APIs, often HTTP/REST.
  5. Services are designed for failure & can tolerate the failure of other services.

15. How does ARP work? Describe ARP spoofing.

Address Resolution Protocol (ARP) is used to map IP addresses to physical MAC addresses on a local network.

Here's how ARP works:

  1. When a device needs to communicate with another device on the local network, it needs the MAC address of the target device.
  2. The sender broadcasts an ARP request to all devices on the network, asking "Who has this IP address?"
  3. The device with the requested IP address sends an ARP reply back to the sender with its MAC address.
  4. The sender caches the IP-to-MAC mapping in its ARP table for future use & sends the packet to the target MAC address.

 

ARP spoofing (or ARP poisoning) is a type of attack where an attacker sends falsified ARP messages over a local network. The attacker aims to associate their MAC address with the IP address of another host, such as the default gateway, causing any traffic meant for that IP address to be sent to the attacker instead. This allows the attacker to intercept, modify, or even stop data in-transit.

16. What is Git & how does it facilitate version control?

Git is a distributed version control system that tracks changes in source code during software development. It allows multiple developers to work on the same project concurrently.

Git facilitates version control by:

  1. Allowing developers to work independently on their own branches & merge changes back when ready.
  2. Providing a complete history of all changes, allowing developers to revert to previous versions if needed.
  3. Enabling collaboration through features like pull requests, where changes can be reviewed before being merged.
  4. Providing features for resolving conflicts when the same part of a file has been changed by multiple developers.

17. Describe design patterns, its types and examples.

Design patterns are reusable solutions to common problems in software design. They provide a general template for solving a problem that can be adapted to fit specific situations. Design patterns are not specific to any programming language but are high-level strategies for structuring code. There are three main types of design patterns:

Creational patterns: These deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Examples include:

  1. Singleton: Ensures a class has only one instance & provides a global point of access to it.
  2. Factory: Defines an interface for creating an object, but let subclasses decide which class to instantiate.

 

Structural patterns: These deal with object composition, creating relationships between objects to form larger structures. For example:

  1. Adapter: Allows classes with incompatible interfaces to work together by wrapping its own interface around that of an existing class.
  2. Decorator: Attaches additional responsibilities to an object dynamically, providing a flexible alternative to subclassing.

 

Behavioral patterns: These deal with communication between objects, assigning responsibilities between objects & encapsulating algorithms. For example:

  1. Observer: Defines a one-to-many relationship between objects so that when one object changes state, all its dependents are notified & updated automatically.
  2. Strategy: Defines a family of algorithms, encapsulates each one, & makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

18. Explain process synchronization & its methods.

Process synchronization is the task of coordinating the execution of processes or threads in a concurrent system, especially when they share resources (like data, files, I/O devices). It ensures that concurrent access to shared resources doesn't lead to unexpected or erroneous behavior.

Methods for process synchronization are:

  1. Locks: Before accessing a shared resource, a process must acquire a lock. It releases the lock when it's done. If another process tries to acquire a locked resource, it must wait until the lock is released.
  2. Semaphores: A semaphore is a variable or abstract data type used to control access to a common resource by multiple processes. It consists of a counter & a queue. If the counter is zero, any process trying to acquire the semaphore is blocked & added to the queue.
  3. Monitors: A monitor is a synchronization construct that allows threads to have both mutual exclusion & the ability to wait (block) for a certain condition to become true. It consists of a mutex (lock) & condition variables.
  4. Message passing: In this method, processes communicate by sending & receiving messages. A process can block when waiting for a message & can have a message queue to store incoming messages.

19. Describe the boot process of a typical operating system.

The boot process of a typical operating system can be divided into several stages:

  1. Power on: The computer is powered on & the BIOS (Basic Input/Output System) initializes the hardware, including the screen & keyboard, & tests the main memory.
  2. BIOS: The BIOS searches, loads, & executes the boot loader program from the boot device (hard disk, SSD, CD, USB).
  3. Boot loader: The boot loader loads the kernel into memory & starts its execution. The most common boot loaders are GRUB for Linux & NTLDR for Windows.
  4. Kernel: The kernel initializes devices & memory, mounts the root file system, & starts the init process.
  5. Init: The init (short for initialization) is the first process started by the kernel. It continues the boot process by starting various services.
  6. Runlevel: Based on the runlevel (a preset configuration), the init process starts the associated services (background processes). For example, runlevel 3 on Linux is a multiuser command-line environment, while runlevel 5 is a multiuser graphical environment.
  7. Login: Once all services are started, the operating system presents a login prompt or GUI for the user to enter credentials.

 

Throughout the boot process, information & error messages may be logged for debugging purposes. Modern operating systems also support hibernation & fast booting where the system state is saved to disk for quicker startup.

20. Explain the concept of VLANs & its advantages.

A Virtual LAN (VLAN) is a logical subnetwork that groups together a collection of devices from different physical LANs. Devices in a VLAN communicate as if they are connected to the same wire, even if they are located on different LAN segments. VLANs work by adding a tag to each Ethernet frame that identifies which VLAN it belongs to. This tag is used by network switches to determine where to send the frame. Devices that belong to the same VLAN can communicate with each other as if they were on the same physical network, regardless of their actual location.

Advantages of VLANs:

  1. Security: VLANs provide a way to logically separate network traffic, which can improve security by isolating sensitive data & limiting the impact of a security breach.
  2. Reduced broadcast traffic: By dividing a network into VLANs, broadcast traffic is contained within each VLAN, reducing unnecessary traffic on the rest of the network.
  3. Flexibility: VLANs allow network administrators to logically group devices based on function, department, or application, regardless of their physical location.
  4. Better performance: VLANs can improve network performance by reducing the size of broadcast domains & limiting the scope of broadcasts.
  5. Cost savings: VLANs can reduce the need for expensive network upgrades by making better use of existing switches & allowing the network to be segmented without buying new hardware.

Advanced Level IBM Interview Questions and Answers

21. What is a deadlock? How can it be prevented?

A deadlock is a situation where two or more processes are unable to proceed because each is waiting for the other to release a resource. The processes are stuck in a circular dependency, permanently blocking each other.

Deadlock can be prevented by below mentioned strategies:

  • Resource Ordering: Make processes request resources in a specific, standardized order.
  • Timeout-Based Mechanisms: Set a time limit for how long a process can wait for a resource.
  • Resource Allocation Graphs: Use a directed graph to model the allocation & requests of resources.
  • Banker's Algorithm: Grant a resource request only if it leaves the system in a safe state.
  • Avoid Circular Wait: Ensure that a circular chain of processes, each waiting for a resource held by the next process, never forms.

22. What are the advantages & disadvantages of using RESTful APIs?

RESTful (Representational State Transfer) APIs are a popular architectural style for designing networked applications. They use HTTP requests to GET, PUT, POST & DELETE data.

Advantages of RESTful APIs:

  1. Simplicity: REST uses standard HTTP methods, making it easy to understand & use.
  2. Flexibility: Data is not tied to resources or methods, so REST can handle multiple types of calls & return different data formats.
  3. Scalability: Stateless nature of REST allows servers to quickly free resources & further simplifies implementation.
  4. Cacheable: Responses can be cached, reducing load on the server & improving performance.
  5. Platform-independent: REST is not tied to any specific platform or language, making it highly adaptable.

 

Disadvantages of RESTful APIs:

  1. Lack of Standards: While REST guidelines exist, they leave a lot of room for interpretation & can lead to inconsistencies between implementations.
  2. No state management: RESTful APIs are stateless, meaning each request must contain all necessary data, leading to repetitive data transmission & increased request overhead.
  3. Increased Complexity for Complex Ops: RESTful APIs can become complex when dealing with non-CRUD (Create, Read, Update, Delete) operations.
  4. Lack of Built-in Security Features: REST does not enforce any specific security mechanisms, leaving it up to the developers to implement them correctly.
  5. Over/under-fetching: With REST, clients often fetch more data than needed (over-fetching) or make multiple requests to fetch all needed data (under-fetching).

23. How does SSL/TLS ensure secure communication over the internet?

SSL (Secure Sockets Layer) & its successor TLS (Transport Layer Security) are cryptographic protocols designed to provide secure communication over a computer network. They operate between the application layer & the transport layer.

SSL/TLS provides three key services:

  • Encryption: Data in transit is encrypted, ensuring that if intercepted, it cannot be read. This uses symmetric encryption.
  • Authentication: The identity of the communicating parties is authenticated using public-key cryptography. This ensures you're communicating with the intended party.
  • Integrity: Message integrity is checked using a message authentication code (MAC). This detects if the data has been tampered with.

 

Here's how SSL/TLS works:

  1. Handshake: The client & server negotiate the version of SSL/TLS, select cryptographic algorithms & authenticate each other using public-key techniques. They also generate shared secrets to establish a uniquely secure connection.
  2. Key Exchange: The client & server exchange keys for symmetric encryption. The public-key encryption is used for this key exchange.
  3. Secure Communication: With the handshake complete & keys exchanged, the client & server can now communicate securely using symmetric encryption.

24. Explain Big-O notation & its significance in algorithms.

Big-O notation is a mathematical notation used to describe the performance or complexity of an algorithm. It specifically describes the worst-case scenario & can be used to describe the execution time or the space used (e.g. in memory or on disk).

In Big-O notation, 'n' represents the size of the input, & the function G(n) is an arbitrary time complexity you're comparing the algorithm to. For example:

  • O(1): Constant time. The algorithm always takes the same time regardless of the size of the input.
  • O(n): Linear time. The execution time increases linearly with the size of the input.
  • O(log n): Logarithmic time. The execution time increases by a constant factor for each doubling of the input size.
  • O(n^2): Quadratic time. The execution time is proportional to the square of the input size.

 

Big-O is significant in algorithms because it allows us to compare the efficiency of different algorithms. It provides a common language to describe performance, independent of machine-specific details. The concept of Big-O is crucial because it helps predict how an algorithm will perform as the input grows larger. This is especially important for large-scale systems where efficiency is critical. It also helps developers make informed decisions about which algorithms to use for a given problem.

25. Explain the concept of paging & its benefits.

Paging is a memory management technique where the computer's main memory is divided into fixed-size blocks called "frames", & the program's virtual memory is divided into blocks of the same size called "pages". When a program needs data from virtual memory, pages are loaded into frames in main memory as needed.

Benefits of paging:

  1. Efficient use of memory: Paging allows the system to load only the necessary parts of a program into main memory, leaving more space for other programs or data.
  2. Faster memory access: Paging reduces fragmentation & allows for faster memory access, as each page can be loaded into any available frame.
  3. Isolation: Each process gets its own page table, providing a level of isolation & protection from other processes.
  4. Virtual memory: Paging is the foundation for implementing virtual memory, allowing programs to use more memory than is physically available.

 

26. Implement a function to merge two sorted linked lists.

struct ListNode {
    int val;
    struct ListNode *next;
};

struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {
    // Create a dummy node to simplify the merging process
    struct ListNode dummy;
    struct ListNode* tail = &dummy;

    // Merge nodes from the two lists in sorted order
    while (l1 && l2) {
        if (l1->val < l2->val) {
            tail->next = l1;
            l1 = l1->next;
        } else {
            tail->next = l2;
            l2 = l2->next;
        }
        tail = tail->next;
    }

    // Append the remaining nodes of l1 or l2
    if (l1) {
        tail->next = l1;
    } else {
        tail->next = l2;
    }

    return dummy.next;
}
You can also try this code with Online C Compiler
Run Code

 

27. Explain process synchronization & its methods.

Process synchronization is the coordination of multiple processes to ensure right execution avoiding race conditions. It involves mechanisms to control the access of shared resources & maintain data consistency. This is necessary when lot of processes or threads access shared data concurrently to prevent data corruption or inconsistent results.

Methods of process synchronization:

  1. Locks: A lock is a synchronization primitive that allows only one process or thread to enter a critical section at a time. It provides mutual exclusion & ensures that only the process holding the lock can access the shared resource.
  2. Semaphores: Semaphores are integer variables used to control access to shared resources. They have two main operations: wait (decrement) & signal (increment). Semaphores can be used for both mutual exclusion & condition synchronization.
  3. Monitors: Monitors are high-level synchronization constructs that encapsulate shared data & provide a set of methods to access & manipulate the data. They ensure that only one process or thread can execute a method on the monitor object at a time.
  4. Message Passing: Message passing is a synchronization mechanism where processes or threads communicate by sending & receiving messages. It allows synchronization through the exchange of messages, which can include data & control information.
  5. Barriers: Barriers are synchronization points where multiple processes or threads must wait until all of them reach the barrier. Once all processes have reached the barrier, they can proceed further, allowing for synchronization & coordination.

28. Implement a queue using two stacks.

class MyQueue:
    def __init__(self):
        self.stack1 = []  # main stack
        self.stack2 = []  # temporary stack

    def push(self, x: int) -> None:
        self.stack1.append(x)

    def pop(self) -> int:
        if not self.stack2:
            while self.stack1:
                self.stack2.append(self.stack1.pop())
        if self.stack2:
            return self.stack2.pop()

    def peek(self) -> int:
        if not self.stack2:
            while self.stack1:
                self.stack2.append(self.stack1.pop())
        if self.stack2:
            return self.stack2[-1]

    def empty(self) -> bool:
        return not self.stack1 and not self.stack2
You can also try this code with Online Python Compiler
Run Code

 

29. What is the difference between kernel-level threads & user-level threads?

Threads are units of execution within a process. They allow a program to perform multiple tasks concurrently. There are two main types of threads: kernel-level threads & user-level threads.

Parameters

Kernel-Level Threads

User-Level Threads

Managed byOperating system kernelUser-level thread library
Kernel awarenessKernel is aware of each threadKernel sees a single process
Context switchRequires kernel interventionHandled entirely in user space
BlockingIf one KLT blocks, others can runIf one ULT blocks, entire process blocks
SpeedSlower context switchesFaster context switches
FlexibilityLess flexibleMore flexible
ScalabilityLimited by kernel resourcesLimited only by user-space resources

 

30. Write a program to find the maximum subarray sum.

#include <stdio.h>
#include <limits.h>

int maxSubarraySum(int arr[], int n) {
    int maxSum = INT_MIN;
    int currentSum = 0;

    for (int i = 0; i < n; i++) {
        currentSum += arr[i];
        
        if (currentSum > maxSum) {
            maxSum = currentSum;
        }
        
        if (currentSum < 0) {
            currentSum = 0;
        }
    }

    return maxSum;
}

int main() {
    int arr[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
    int n = sizeof(arr) / sizeof(arr[0]);

    int maxSum = maxSubarraySum(arr, n);
    printf("The maximum subarray sum is: %d\n", maxSum);

    return 0;
}
You can also try this code with Online C++ Compiler
Run Code

 

Kadane's algorithm has a time complexity of O(n), as it makes a single pass through the array. The space complexity is O(1), as it uses only a few variables regardless of the size of the input.

Conclusion

We hope you have gained some insights on IBM Interview Questions through this article. We understand that preparing for interviews can be nerve-wracking and hope these IBM Interview Questions will help you during your interviews and you learn and grow in your role!  

You can also practice coding questions commonly asked in interviews on Coding Ninjas Code360

Also, check out some of the Guided Paths on topics such as Data Structure and AlgorithmsCompetitive ProgrammingOperating SystemsComputer Networks, DBMSSystem Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.

Live masterclass