IBM Sample Placement Paper & Questions
Practicing sample placement papers is an important part of preparation for the IBM hiring exam. The IBM assessment primarily consists of coding problems and an English language test. Working through sample questions helps candidates understand the question format, difficulty level, and time management required for the actual exam.
IBM Placement Questions - Sample Question Paper
1.
1. A number of bids are received for a project.
Determine the number of distinct pairs of project costs where their absolute difference is equal to a given target value.
Two pairs are distinct if they differ in at least one value.
Constraint:
(1 ≤ target ≤ 10^9)
INPUT:
Example 1
N = 3
projectCosts = [1, 3, 5]
target = 2
Example 2
N = 5
projectCosts = [1, 5, 3, 4, 2]
target = 2
Example 1 Output
2
Explanation:
Pairs with difference 2 are: [1,3], [3,5]
Therefore, output = 2
Example 2 Output
3
Explanation:
Pairs with difference 2 are: [1,3], [3,5], [2,4]
Therefore, output = 3
C++ Code
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
int target;
cin >> target;
unordered_set<int> s;
for (int x : arr) s.insert(x);
int count = 0;
for (int x : s) {
if (s.count(x + target)) {
count++;
}
}
cout << count;
return 0;
}Java Code
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = sc.nextInt();
int target = sc.nextInt();
Set<Integer> set = new HashSet<>();
for (int x : arr)
set.add(x);
int count = 0;
for (int x : set) {
if (set.contains(x + target))
count++;
}
System.out.println(count);
}
}2.
2. Convert a given word into Pig Latin using the following rules:
1.If the word starts with a vowel, add "ay" to the end.
Example: apple → appleay
2.If the word starts with consonants, move all characters before the first vowel to the end and add **"ay". Example: glove → oveglay`
3.If no vowel exists, simply append "ay".
Example: rhythm → rhythmay
string toPigLatin(const string &word) {
// if the word starts with a vowel
if (isVowel(word[0])) {
return word + "ay";
}
// find the position of the first vowel
int pos = -1;
for (int i = 0; i < word.size(); i++) {
if (isVowel(word[i])) {
pos = i;
break;
}
}
// if no vowel is found, treat whole word as consonant cluster
if (pos == -1) {
return word + "ay";
}
// split and transform
string start = word.substr(0, pos);
string rest = word.substr(pos);
return rest + start + "ay";
}Input word = "glove"
C++ Code
#include <bits/stdc++.h>
using namespace std;
bool isVowel(char c) {
c = tolower(c);
return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u');
}
string toPigLatin(const string &word) {
if (isVowel(word[0]))
return word + "ay";
int pos = -1;
for (int i = 0; i < word.size(); i++) {
if (isVowel(word[i])) {
pos = i;
break;
}
}
if (pos == -1)
return word + "ay";
string start = word.substr(0, pos);
string rest = word.substr(pos);
return rest + start + "ay";
}
int main() {
string word;
cin >> word;
cout << toPigLatin(word);
}Java Code
import java.util.*;
public class Main {
static boolean isVowel(char c) {
c = Character.toLowerCase(c);
return "aeiou".indexOf(c) != -1;
}
static String toPigLatin(String word) {
if (isVowel(word.charAt(0)))
return word + "ay";
int pos = -1;
for (int i = 0; i < word.length(); i++) {
if (isVowel(word.charAt(i))) {
pos = i;
break;
}
}
if (pos == -1)
return word + "ay";
String start = word.substring(0, pos);
String rest = word.substring(pos);
return rest + start + "ay";
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String word = sc.next();
System.out.println(toPigLatin(word));
}
}Output
oveglay
3.
3. You are given an array of integers. Return the number of strictly increasing subsequences of length 3 (modulo (10^9 + 7)).**
Note:
A subsequence is a sequence that can be derived from an array by deleting zero or more elements without changing the order of the remaining elements.
Example 1
Input:
n = 5
arr = [1, 2, 3, 4, 1],
CODING
import java.util.*;
class Result {
static final long MOD = 1000000007;
public static int countIncreasingTriplets(int[] arr) {
int n = arr.length;
long count = 0;
// For each element as middle element
for (int j = 0; j < n; j++) {
long leftSmaller = 0;
long rightGreater = 0;
// Count elements smaller than arr[j] on the left
for (int i = 0; i < j; i++) {
if (arr[i] < arr[j]) {
leftSmaller++;
}
}
// Count elements greater than arr[j] on the right
for (int k = j + 1; k < n; k++) {
if (arr[k] > arr[j]) {
rightGreater++;
}
}
count = (count + (leftSmaller * rightGreater) % MOD) % MOD;
}
return (int) count;
}
// For testing
public static void main(String[] args) {
int[] arr1 = {1, 2, 3, 4, 1};
System.out.println(countIncreasingTriplets(arr1)); // Output: 4
int[] arr2 = {3, 1, 4, 5};
System.out.println(countIncreasingTriplets(arr2)); // Output: 2
}
}C++ CODE
#include <bits/stdc++.h>
using namespace std;
int countIncreasingTriplets(vector<int>& arr) {
const long long MOD = 1e9 + 7;
int n = arr.size();
long long count = 0;
for (int j = 0; j < n; j++) {
long long left = 0, right = 0;
for (int i = 0; i < j; i++)
if (arr[i] < arr[j]) left++;
for (int k = j + 1; k < n; k++)
if (arr[k] > arr[j]) right++;
count = (count + left * right) % MOD;
}
return count;
}Output:
4
Some subsequences of length 3 (0-based indexing):
Index of 1st Element | Index of 2nd Element | Index of 3rd Element | Subsequence | Strictly Increasing
0 | 1 | 2 | [1, 2, 3] | Yes
0 | 1 | 3 | [1, 2, 4] | Yes
0 | 2 | 3 | [1, 3, 4] | Yes
1 | 2 | 3 | [2, 3, 4] | Yes
All strictly increasing subsequences of length three are:
[1, 2, 3], [1, 2, 4], [1, 3, 4], and [2, 3, 4].
The answer is 4 modulo (10^9 + 7), which is 4.
Example 2
Input:
n = 4
arr = [3, 1, 4, 5]
Output:
2
There are two strictly increasing subsequences of length three:
[3, 4, 5] and [1, 4, 5].
Frequently Asked QuestionsFAQ
Are these questions from previous IBM exams?
These sample questions are designed based on the pattern and difficulty level observed in the IBM Associate Systems Engineer hiring exam. They are practice questions aligned with the actual exam format and are not directly taken from any specific previous exam.
How similar are these questions to the actual IBM exam?
These questions follow the same format, topic distribution, and difficulty level as reported by candidates who have appeared for the IBM hiring exam. The actual exam may have variations in specific questions, but the overall pattern remains consistent.
How often are IBM sample papers updated?
Sample papers are updated periodically to reflect any changes in the IBM exam pattern or assessment format. Candidates should check for the latest updates before appearing for the exam.
What is the overall difficulty level of the IBM exam?
The coding round is rated medium to hard in difficulty, primarily testing arrays, strings, and algorithmic problem-solving. The English assessment is easy to moderate. The overall difficulty is moderate when considering all sections together.
Can I switch between questions during the IBM exam?
The ability to navigate between questions depends on the specific assessment platform and configuration. For the HackerRank coding assessment, candidates can typically switch between the two coding problems. For the English assessment, navigation rules may vary by drive.
Is there negative marking in the IBM exam?
There is no negative marking in the coding assessment section. However, negative marking applies in the English language assessment. Candidates should attempt the English section carefully and skip questions they are unsure about.
What is the mode of the IBM exam?
The IBM exam is conducted in online mode. The coding assessment is conducted on the HackerRank platform, and the English assessment uses IBM's own platform. Both require a stable internet connection and a compatible browser.
How many coding questions are there in the IBM exam?
The IBM coding assessment typically includes 2 coding problems to be solved in approximately 50-55 minutes. Some drives may also include 3-5 technical MCQs alongside the coding problems.
Which programming languages are allowed in the IBM coding exam?
The permitted programming languages for the IBM HackerRank coding assessment are C, C++, Java, and Python. Candidates can choose any one of these languages to solve the coding problems.
