IBM Coding Questions and Answers 2025
IBM Coding Questions with Solutions
IBM Coding Questions 2025 section provides a full set of IBM coding round questions with answers and explanations. Here, you will get the latest IBM coding challenges, IBM programming questions, and coding test modules that are part of the IBM Placement Exam 2025 and IBM Online Coding Round.
This section is designed to help you prepare for the IBM hiring process with practice questions, detailed solutions, and updated exam patterns.

IBM Coding Test Questions and Answers 2025
IBM Coding Questions | 2 Questions |
Total Time | 55 mins |
Types of Test | Non Adaptive |
Negative Marking | No |
Programming Languages:
- C
- C++
- JAVA
- Python
IBM Programming Previous Year Questions and Answers
Practicing these IBM coding questions and answers will help you understand the difficulty level, question pattern, and important coding topics asked in the IBM recruitment process.
Here are 3 simple and effective tips for solving IBM coding questions:
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
IBM Coding Questions and Answers
1. Write a program to find HCF of two numbers by without using recursion.
Input format: The first line contains any 2 positive numbers separated by space.
Output format:
- Print the HCF of given two numbers.
Sample Input:
- 70 15
Sample Output:
- 5
#include<iostream> int gcd(int,int); int main() { int m,n,ans; scanf("%d",&m); scanf("%d",&n); while(m!=n) { if(m>n) { m=m-n; } else { n=n-m; } } printf("%d",m); return 0; }
Q2. Consider a string, S, that is a series of characters, each followed by its frequency as an integer.
The string is not compressed correctly, so there may be multiple occurrences of the same character.
A properly compressed string will consist of one instance of each character in alphabetical order followed by the total count of that character within the string.
import java.util.*; public class Main { public static String properCompression(String s) { StringBuilder compressedStr = new StringBuilder(); for (int i = 0; i < s.length(); i += 2) { char c = s.charAt(i); int count = Character.getNumericValue(s.charAt(i + 1)); while (count > 0) { compressedStr.append(c); count--; } } return compressedStr.toString(); } public static void main(String[] args) { String inputStr = "a3b5c2a2"; String compressedResult = properCompression(inputStr); System.out.println(compressedResult); // Output: "aaabbbbbcc" } }
Q3. Write a C++ Program to Change Decimal Number to Binary?
#include<iostream>
namespace std;
int main ()
{
int a[10], n, i;
cout << "Enter the number to convert: ";
cin >> n;
for (i = 0; n > 0; i++)
{
a[i] = n % 2;
n = n / 2;
}
cout << "Binary of the given number= ";
for (i = i - 1; i >= 0; i--)
{
cout << a[i];
}
}
Q 4. C++ Program to generate Fibonacci Triangle
#include<iostream> using namespace std; int main() { int a=0,b=1,i,c,n,j; cout<<"Enter the limit: "; cin>>n; for(i=1; i<=n; i++) { a=0; b=1; cout<<b<<"\t"; for(j=1; j<i; j++) { c=a+b; cout<<c<<"\t"; a=b; b=c; } cout<<"\n"; } return 0; }
Q 5. What is the Output of the program
Using namespace std; int main() { int a=5,b=10,c=15; int*arr[]={&a,&b,&c}; cout<<arr[1]; return 0; }
- 5
- 10
- 15
- It will print their address of variable b.
Q 6. What is the Output of the program
Using namespace std; int main() { Char arr[20]; int i; for(i=0;i<10;i++) *(arr+i)=65 +1; *(arr+i)=0; cout<<arr; return(o); }
- ABCDEFGHIJ
- AAAAAAAAAA
- JJJJJJJJ
- None of the above
Solution:-A
Q 7. What is the Output of the program
#include<iostream> Using namespace std; int main() { char*ptr; Char Str[]="abcdefg"; ptr=Str; ptr+=5; cout<<ptr; return 0; }
- fg
- cdef
- defg
- abcd
Q8. For each element of an array of non-negative integers, arrin], is calculated as:
- prefli] = arr[1JIJ⊕ arrl2JIJO . . . ⊕arrli]
- Here x ⊕ y is the bitwise XOR of x and y.
The array pref[n] contains the prefix XOR of all elements in arr[n]where 1 s is n:
1
2
Given the array pref, find the original array arr.
Note: There is always a unique arr for a given pref.
public class Main { public static int[] findOriginalArray(int[] pref) { int n = pref.length; int[] arr = new int[n]; arr[0] = pref[0]; for (int i = 1; i < n; i++) { arr[i] = pref[i] ^ pref[i - 1]; } return arr; } public static void main(String[] args) { int[] pref = {3, 5, 2, 10}; int[] originalArray = findOriginalArray(pref); System.out.print("Original Array: "); for (int num : originalArray) { System.out.print(num + " "); } // Output: Original Array: 3 8 10 2 } }
FAQ's related to IBM Coding Questions
Question 1: What is the Difficulty Level of the Coding Paper of IBM?
Answer: Coding paper difficulty is Medium to High is IBM Coding Test. If you want to prepare you can Prepare from our website Prepinsta.com
Question 2: In Which Languages You can solve the IBM Coding Test Paper?
Answer: You Can use these langugaes to solve Coding Test of IBM….
- C
- C++
- JAVA
- Python
Question 3: How to Prepare for IBM Coding Test Paper?
Answer: You can Visit our website for IBM Coding Test paper.You will get many questions to solve the paper.
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others


30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
By reading the qn,I think the code for Q2 is wrong.
import java.util.*;
public class Main {
public static String properCompression(String s) {
StringBuilder compressedStr = new StringBuilder();
int freq[] = new int[26];
for(int i=0;i<s.length();i+=2){
freq[s.charAt(i)-'a']+=(s.charAt(i+1)-'0');
}
for (int i = 0; i < 26; i ++) {
char c = (char)(i+'a');
int count = freq[i];
if(count!=0)compressedStr.append(c+""+count);
}
return compressedStr.toString();
}
public static void main(String[] args) {
String inputStr = "a3b5c2a2";
String compressedResult = properCompression(inputStr);
System.out.println(compressedResult); // Output: "a5b5c2"
}
}
Please join our discord community for the technical support.
where are the previous year qns
Hey!
Kindly refer IBM PYQ’s. Also if you want to prepare for IBM, text us right away at 8448440710.
This is good experience for me
And this is good
Hey💖
We are so glad that you liked it.☺
this all program is sufficient for IBM coding round??