Published: 26 Oct 2024
Reading Time: 3 min read
International Business Machines Corporation (IBM) is a leading American multinational technology company with a presence in over 175 countries. Founded in 1911, IBM is known for its innovations in computing, including the automated teller machine (ATM) and relational database. As the largest industrial research organization, it has held the record for the most annual U.S. patents for 29 years.
IBM's focus on quantum computing, artificial intelligence, and data infrastructure underscores its commitment to shaping the tech landscape. The IBM software developer coding round questions are crucial for evaluating candidates, making it a key step in recruitment.
Candidates can expect a range of topics during IBM coding assessments, including:
Candidates can expect these IBM coding questions with answers for software developers:
Given a string s, find the number of unique characters in the string.
Input Format:
Output Format:
Example:
Input
3
hello
world
python
Output
4
5
6
C++ Solution:
#include <iostream>
#include <unordered_set>
#include <string>
int main() {
int T;
std::cin >> T;
while (T--) {
std::string s;
std::cin >> s;
std::unordered_set<char> unique_chars(s.begin(), s.end());
std::cout << unique_chars.size() << std::endl;
}
return 0;
}
Given an array of integers, find the maximum sum of a contiguous subarray.
Input Format:
Output Format:
Example:
Input
2
5
-2 1 -3 4 -1 2 1 -5 4
4
1 -2 3 -4
Output
6
3
C++ Solution:
#include <iostream>
#include <vector>
#include <algorithm>
int maxSubArray(const std::vector<int>& nums) {
int max_sum = nums[0];
int current_sum = nums[0];
for (size_t i = 1; i < nums.size(); ++i) {
current_sum = std::max(nums[i], current_sum + nums[i]);
max_sum = std::max(max_sum, current_sum);
}
return max_sum;
}
int main() {
int T;
std::cin >> T;
while (T--) {
int n;
std::cin >> n;
std::vector<int> nums(n);
for (int i = 0; i < n; ++i) {
std::cin >> nums[i];
}
std::cout << maxSubArray(nums) << std::endl;
}
return 0;
}
Write a function to check if a given string is a palindrome. A palindrome is a string that reads the same backward as forward.
Input Format:
Output Format:
Example:
Input
3
madam
hello
racecar
Output
YES
NO
YES
C++ Solution:
#include <iostream>
#include <string>
bool isPalindrome(const std::string &s) {
int left = 0, right = s.size() - 1;
while (left < right) {
if (s[left] != s[right]) {
return false;
}
left++;
right--;
}
return true;
}
int main() {
int T;
std::cin >> T;
while (T--) {
std::string s;
std::cin >> s;
std::cout << (isPalindrome(s) ? "YES" : "NO") << std::endl;
}
return 0;
}
Given two strings, determine if they are anagrams of each other. Two strings are anagrams if they contain the same characters with the same frequencies.
Input Format:
Output Format:
Example:
Input
3
listen silent
hello world
evil vile
Output
YES
NO
YES
C++ Solution:
#include <iostream>
#include <string>
#include <unordered_map>
bool areAnagrams(const std::string &s1, const std::string &s2) {
if (s1.size() != s2.size()) return false;
std::unordered_map<char, int> char_count;
for (char c : s1) {
char_count[c]++;
}
for (char c : s2) {
char_count[c]--;
if (char_count[c] < 0) return false;
}
return true;
}
int main() {
int T;
std::cin >> T;
while (T--) {
std::string s1, s2;
std::cin >> s1 >> s2;
std::cout << (areAnagrams(s1, s2) ? "YES" : "NO") << std::endl;
}
return 0;
}
Given a string, count the number of vowels in it.
Input Format:
Output Format:
Example:
Input
Hello World
Output
3
C++ Solution:
#include <iostream>
#include <string>
int countVowels(const std::string& s) {
int count = 0;
for (char c : s) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
count++;
}
}
return count;
}
int main() {
std::string s;
std::getline(std::cin, s); // Read the entire line of input
std::cout << countVowels(s) << std::endl;
return 0;
}
Determine if a given integer is a prime number.
Input Format:
Output Format:
Example:
Input
29
Output
YES
C++ Solution:
#include <iostream>
bool isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) return false;
}
return true;
}
int main() {
int n;
std::cin >> n;
std::cout << (isPrime(n) ? "YES" : "NO") << std::endl;
return 0;
}
Merge two sorted arrays into one sorted array.
Input Format:
Output Format:
Example:
Input
3 4
1 3 5
2 4 6 8
Output
1 2 3 4 5 6 8
C++ Solution:
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> arr1(n), arr2(m);
for (int i = 0; i < n; ++i) std::cin >> arr1[i];
for (int i = 0; i < m; ++i) std::cin >> arr2[i];
std::vector<int> merged(n + m);
std::merge(arr1.begin(), arr1.end(), arr2.begin(), arr2.end(), merged.begin());
for (int num : merged) {
std::cout << num << " ";
}
return 0;
}
Calculate the nth Fibonacci number.
Input Format:
Output Format:
Example:
Input
10
Output
55
C++ Solution:
#include <iostream>
int fibonacci(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
int a = 0, b = 1, c;
for (int i = 2; i <= n; ++i) {
c = a + b;
a = b;
b = c;
}
return b;
}
int main() {
int n;
std::cin >> n;
std::cout << fibonacci(n) << std::endl;
return 0;
}
To excel in the IBM coding interviews, consider the following tips:
In conclusion, solving IBM coding questions for software developers is crucial for candidates who want to get a job at IBM. By focusing on common topics, practicing regularly, and using effective problem-solving strategies, you can significantly improve your chances of success in IBM coding assessments.
Commonly, candidates face questions related to data structures, algorithms, and general problem-solving.
Platforms like Nxtwave LastMinutePro, Leetcode, and HackerRank often host IBM coding questions, making them an excellent resource for preparation.