Back

IBM Coding Assessment: Common Questions and Expert Answers

26 Oct 2024
4 min read

IBM or International Business Machines Corporation is a global leader in technology and consulting, providing innovative solutions in areas such as cloud computing, AI, and quantum computing. Over the last century, IBM has consistently positioned itself at the top of technological advancements, shaping the future of industries worldwide. Its commitment to research and development has developed a culture of innovation, making it a sought-after employer for tech enthusiasts.

Importance of IBM Coding Interviews in Recruitment

Coding interviews are a crucial part of IBM’s recruitment process, especially for technical roles. IBM coding questions assess candidates' problem-solving abilities, programming skills, and understanding of algorithms and data structures. These interviews are designed to identify individuals who can drive the company’s innovative projects and solve complex problems. Successfully tackling these challenges reflects adaptability, and creativity to thrive in the dynamic environment.

Top Coding Questions and Answers 2024

While preparing for the IBM coding assessment round, candidates should familiarize themselves with these common topics. These include:

Data Structures

  • Arrays
  • Linked lists
  • Stacks
  • Queues
  • Trees
  • Graphs

Algorithms

  • Sorting
  • Searching
  • Dynamic programming
  • Backtracking

Mathematical Problems

  • Basic arithmetic
  • Number theory
  • Combinatorics

String Manipulation

  • String parsing
  • Substring search
  • Regular expressions

Top IBM Coding Questions 2024

1. Write a program to find the HCF of two numbers without using recursion. 

Example 

Input 
70 15

Output 
5

#include <stdio.h>

int main() {
    int m, n;
    scanf("%d %d", &m, &n);
    
    while (m != n) {
        if (m > n) {
            m = m - n;
        } else {
            n = n - m;
        }
    }
    printf("%d", m);
    return 0;
}

2. Write a program to find the factorial of a number.

Example

Input
5

Output
Factorial of 5 = 120

C

#include <stdio.h>

int main() {
    int n;
    unsigned long long factorial = 1;
    
    printf("Enter a positive integer: ");
    scanf("%d", &n);
    
    for (int i = 1; i <= n; ++i) {
        factorial *= i;
    }
    
    printf("Factorial of %d = %llu\n", n, factorial);
    return 0;
}

3. Given a string of characters followed by their frequency, compress it into a proper format.

Example 

Input 
a3b5c2a2

Output
abc

C

#include <stdio.h>
#include <string.h>

void properCompression(const char *s, char *result) {
    int freq[256] = {0}; // Frequency array for ASCII

    for (int i = 0; s[i] != '\0'; i += 2) {
        char c = s[i];
        int count = s[i + 1] - '0';
        freq[c] += count;
    }

    int index = 0;
    for (char c = 'a'; c <= 'z'; c++) {
        if (freq[c] > 0) {
            result[index++] = c;
        }
    }
    result[index] = '\0';
}

int main() {
    char inputStr[] = "a3b5c2a2";
    char compressedResult[100];
    properCompression(inputStr, compressedResult);
    printf("%s\n", compressedResult);
    return 0;
}

4. Write a program to calculate the sum of digits of a number.

Example

Input
12345

Output 
15

C

#include <stdio.h>

int main() {
    int n, sum = 0;
    printf("Enter a number: ");
    scanf("%d", &n);
    
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    
    printf("Sum of digits: %d\n", sum);
    return 0;
}

5. Write a C program to convert the Decimal to a Binary number

Example

Input
10

Output
Binary of the given number = 1010

C

#include <stdio.h>

int main() {
    int n;
    printf("Enter the number to convert: ");
    scanf("%d", &n);
    
    int binary[32], i = 0;
    while (n > 0) {
        binary[i] = n % 2;
        n = n / 2;
        i++;
    }
    
    printf("Binary of the given number = ");
    for (i = i - 1; i >= 0; i--) {
        printf("%d", binary[i]);
    }
    return 0;
}
₹ 49,000
strip
₹ 33,000
/-
Karthik was able to transform his career from a boring job to an exciting job in software!
Talk to a career expert
intensive student
emoji

6. What is the output of the following program?

Example

Input
No input is required

Output
10

C

#include <stdio.h>

int main() {
    int a = 5, b = 10, c = 15;
    int *arr[] = {&a, &b, &c};
    printf("%d\n", *arr[1]);
    return 0;
}

7. Given an array of prefix XOR values, reconstruct the original array.

Example

Input
3 5 2 10

Output
Original Array: 3 8 10 2

C

#include <stdio.h>

void findOriginalArray(int pref[], int n, int arr[]) {
    arr[0] = pref[0];
    for (int i = 1; i < n; i++) {
        arr[i] = pref[i] ^ pref[i - 1];
    }
}

int main() {
    int pref[] = {3, 5, 2, 10};
    int n = sizeof(pref) / sizeof(pref[0]);
    int originalArray[4];
    findOriginalArray(pref, n, originalArray);
    
    printf("Original Array: ");
    for (int i = 0; i < n; i++) {
        printf("%d ", originalArray[i]);
    }
    printf("\n");
    return 0;
}

8. Write a program to reverse a given string.

Example

Input
nxtwave

Output
evawtxn

C

#include <stdio.h>
#include <string.h>

int main() {
    char str[100];
    printf("Enter a string: ");
    gets(str);
    
    int n = strlen(str);
    for (int i = n - 1; i >= 0; i--) {
        printf("%c", str[i]);
    }
    printf("\n");
    return 0;
}

9. Write a program to check if a number is prime.

Example

Input
29

Output
Prime

C

#include <stdio.h>

int main() {
    int n, isPrime = 1;
    printf("Enter a number: ");
    scanf("%d", &n);
    
    if (n <= 1) isPrime = 0;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            isPrime = 0;
            break;
        }
    }
    
    if (isPrime) printf("Prime\n");
    else printf("Not Prime\n");
    return 0;
}

10. Write a program to count the number of vowels in a given string

Input
Hello World

Output
Number of vowels: 3

C

#include <stdio.h>

int main() {
    char str[100];
    int count = 0;
    
    printf("Enter a string: ");
    gets(str);
    
    for (int i = 0; str[i] != '\0'; i++) {
        char ch = str[i];
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
            ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
            count++;
        }
    }
    
    printf("Number of vowels: %d\n", count);
    return 0;
}

Tips to Crack IBM Coding Assessment

Here are some essential tips to help you excel in IBM coding assessments:

  • Familiarize yourself with the structure and types of questions on platforms like Hackerrank.
  • Practice above mentioned topics such as arrays, strings, recursion, sorting algorithms, and data structures.
  • Use Hackerrank for practice problems specifically designed for IBM assessments.
  • Look for shared experiences and solutions from previous candidates.
  • Write efficient code and discuss time/space complexity.
  • Engage in mock coding interviews to simulate pressure.
  • Utilize compilations of IBM coding questions and answers.
  • Manage your time effectively during assessments.

Conclusion

In conclusion, preparing for IBM coding questions, especially for positions like Associate System Engineer, requires a lot of practice, understanding, and time management. By utilizing the right resources, and focusing on common topics, you can increase your chances of success in IBM coding assessments.

₹ 49,000
strip
₹ 33,000
/-
Karthik was able to transform his career from a boring job to an exciting job in software!
Talk to a career expert
intensive student
emoji

Frequently Asked Questions

1. How do I prepare for IBM coding and technical rounds?

Practice coding problems on platforms like Hackerrank, review previous year's questions and engage in mock interviews to build confidence and improve your coding skills.

2. What should I do if I get stuck on a problem?

Break the problem down into smaller parts, and try to implement a brute force solution first. If that doesn't work, move on to the next question and come back if time permits.

Read More Articles

Chat with us
Chat with us
Talk to career expert