IBM Associate System Engineer Coding Questions 2023 | ASE Coding Questions For IBM | IBM ASE Coding Questions with Answers PDF | IBM Online Coding Round Questions & Answers | IBM Coding Questions
IBM Associate System Engineer Coding Questions 2023 | IBM Coding Challenge Questions: IBM is a major company and one of the top recruiters. If you want to work at IBM and are wondering how to prepare for IBM Associate System Engineer Coding Round Questions, we can help. In this blog, we addressed some sample IBM Associate System Engineer Coding Round and Answers that may be asked in IBM. We will explore IBM Associate System Engineer Coding Questions in this post, and IBM offers a unique technique for measuring a candidate’s problem-solving skills. On their blog, they hold coding challenges throughout the year. If you succeed in the challenge, you may be invited to an interview. This article will teach you all you need to know about IBM Coding. To get more Private Jobs, click here
Also, Check Out | |
IBM Aptitude Interview Questions and Answers PDF | IBM Coding Questions and Answers 2023 |
IBM Associate System Engineer Syllabus 2023-24 (Updated) |
Notification Details | |||||
---|---|---|---|---|---|
Recruiter | IBM | ||||
Designation | Associate System Engineer | ||||
Job Location | Across India | ||||
Vacancies/Post | Multiple | ||||
Join our Telegram |
IBM Associate System Engineer Coding Questions For Freshers
- Reverse a string in Java
- How to swap two numbers without using a temporary variable?
- Program to find the LCM of two numbers
- Write a program that concatenates two strings in C++.
- Given an integer, write a function that returns true if the given number is a palindrome, else false. For example, 12321 is a palindrome, but 1451 is not a palindrome.
IBM Associate System Engineer Coding Questions For Eperienced
Questions
Predict the output:
#include <bits/stdc++.h>
int main()
{
int a=0;
if(a++)
{
std::cout<<"Hello";
}
else{
std::cout<<"Goodbye";
}
return 0;
}
1. Syntax error
2. Runtime error
3. Hello
4. Goodbye
Questions
People tend to get confused since there is no condition for ‘if’. However, it is straightforward. The value of ‘a’ is initialized as 0. Now, if the result of whatever we write is 0, it is considered false, while every non-zero result will be true. In post-increment, the value is checked before updation. So the condition will be false, and the else condition will print Goodbye.
Q) What is the syntax for command-line arguments?
1. int main(char c, int arg)
2. int main(int var, char*argv[])
3. int main(int v, char c)
4. int main(char*arv[], int arg[])
Questions
The syntax for command-line arguments is int main(int var, char*argv[]), where var is a positive integer variable to store the number of arguments passed by users (including the program name). The ‘argv’ or the argument vector, on the other hand, is an array for character pointers and lists all arguments. ‘argv[0] is the program name and all elements till argv[var-1] are command-line arguments.
Q) Arrays are also known as:
1. Identical variables
2. Variable collectives
3. Similar quantity variables
4. Subscripted variables
Questions
Merge sort divides the array into two halves and then merges both halves in linear time. Therefore the worst, average and best case time complexity will be O(n*Log n).
Q) How many moves are needed to solve the Tower of Hanoi puzzle?
1. 2^(n)-1
2. 2^(n)+1
3. 2^n
4. n^2
Questions
The bracket operator is executed before the assignment operator due to higher precedence. The result will always be from the last expression assigned when evaluated left to right.
Q) The in-order traversal of a binary tree is M J N H R K S, and its pre-order traversal is H J M N K R S. Accordi
IBM Associate System Engineer Coding Questions & Answers 2023
Q) Write a program to find the sum of A.P series
Examples:
Input : a = 1 d = 2 n = 4
Output : 16 1 + 3 + 5 + 7 = 16
Algorithm:
Sum of arithmetic series is ((n / 2) * (2 * a + (n - 1) * d)) Where a is First term d is Common difference n is No of terms
Implementation:
#include<bits/stdc++.h> using namespace std; // Function to find sum of series. float sumOfAP(float a, float d, int n) { float sum = 0; for (int i=0;i<n;i++) { sum = sum + a; a = a + d; } return sum; } int main() { int n = 4; float a = 1, d = 2; cout<<sumOfAP(a, d, n); return 0; }
Q) Write a C++ Program to Change Decimal Number to Binary?
ANSWER:
#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) Write a C++ Program to generate Fibonacci Triangle
ANSWER:
#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) Given a number n, print n-th Fibonacci Number
ANSWER:
#include <bits/stdc++.h> using namespace std; int fib(int n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); } int main() { int n = 9; cout << fib(n); getchar(); return 0; }
Q) Write a program to find HCF of two numbers by without using recursion
Examples:
Input: x = 16, y = 32
Output: 16
Input: x = 12, y = 15
Output: 3
Algorithm:
- Check if smaller of two number divide larger number. If yes, HCF is smaller
- Else, Start from smaller/2 to 1 and check if current number divides both the input numbers.
- If yes, then current number is required HCF.
Implementation:
#include <iostream> using namespace std; int findHCF(int x, int y) { // Find minimum of two numbers int smallest = min(x, y); // If both numbers divisible by smallest number, // then smallest is the HCF. if (x % smallest == 0 && y % smallest == 0) return smallest; // Loop through smallest/2 to 1 and // check if number divides both input numbers for (int i = smallest / 2; i >= 2; i--) { if (x % i == 0 && y % i == 0) return i; } // If no number divides then HCF is 1. return 1; } int main() { int x = 16, y = 32; cout << findHCF(x, y); return 0; }
Q) Write a program to find HCF of two numbers without using recursion
ANSWER:
#include<stdio.h> 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; }
Q) Given a number x, determine whether the given number is Armstrong Number or not.
ANSWER:
#include <iostream> using namespace std; int main() { int n = 153; int temp = n; int p = 0; while (n > 0) { int rem = n % 10; p = (p) + (rem * rem * rem); n = n / 10; } if (temp == p) { cout<<("Yes. It is Armstrong No."); } else { cout<<("No. It is not an Armstrong No."); } return 0; }
Q) Program to check if a given year is leap year
ANSWER:
#include <bits/stdc++.h> using namespace std; bool checkYear(int year) { if (year % 400 == 0) return true; if (year % 100 == 0) return false; if (year % 4 == 0) return true; return false; } int main() { int year = 2000; checkYear(year) ? cout << "Leap Year": cout << "Not a Leap Year"; return 0; }
Q) Write a program to reverse digits of a number
ANSWER:
#include <bits/stdc++.h> using namespace std; int reverseDigits(int num) { int rev_num = 0; while (num > 0) { rev_num = rev_num * 10 + num % 10; num = num / 10; } return rev_num; } int main() { int num = 4562; cout << "Reverse of no. is " << reverseDigits(num); getchar(); return 0; }
Q) Print all prime numbers less than or equal to N
ANSWER:
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } void printPrime(int n) { for (int i = 2; i <= n; i++) if (isPrime(i)) cout << i << " "; } int main() { int n = 7; printPrime(n); }
Q) C++ Program to generate Fibonacci Triangle
ANSWER:
#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) Khaled has an array A of N elements. It is guaranteed that N is even. He wants to choose at most N/2 elements from array A. It is not necessary to choose consecutive elements. Khaled is interested in XOR of all the elements he chooses. Here, XOR denotes the bitwise XOR operation.
For example:
- If A=[2,4,6,8], then khaled can choose the subset [2,4,8] to achieve XOR=(2 XOR 4 XOR 8)=14.
Khaled wants to maximize the XOR of all the elements he chooses. Your task is to help khaled to find the max XOR of a subset that he can achieve by choosing at most N/2 elements?
Input format:
- The first line contains an integer, N, denoting the number of elements in A.
- Each line i of the N subsequent lines(where 0<=i<=N) contains an integer describing Ai.
Constraints
- 1<=N<=120
- 1<=A[i]<=10^6
Sample Input 1
2
1
2
Sample Output 1
2
Explanation:
N=2, A=[1,2] khaled can choose the subset[2]. The xor of the elements in the subset is 2. And the number of elements in the subset is 1 which is less than N/2.
Sample Input 2
4
1
2
4
7
Sample Output 2
7
Explanation:
N=4, A=[1,2,4,7] Khaled can choose the subset [7]. The xor of the elements in the subset is 7, and the number of elements in the subset is 1 which is less than N/2.
EXAMPLE PROGRAMS
C++ PROGRAM
#include<bits/stdc++.h> using namespace std; int main () { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int M = 1 << 20; int dp[M]; char res[M]; for (int i = 1; i < M; i++) dp[i] = INT_MAX; for (int i = 0; i < n; i++) { if (arr[i] == 0) continue; for (int j = 0; j < M; j++) res[j] = 0; for (int k = 0; k < M; k++) { if (res[k] == 1) continue; if (dp[k] > dp[k ^ arr[i]]) dp[k] = dp[k ^ arr[i]] + 1; else if (dp[k ^ arr[i]] > dp[k]) dp[k ^ arr[i]] = dp[k] + 1; res[k ^ arr[i]] = 1; } } int j = M - 1, k = n >> 1; while (dp[j] > k) j--; cout << j; return 0; }
PYTHON PROGRAM
from itertools import combinations def fun(arr, N): sub = [] max_xor = max(arr) for i in range(1, N // 2): comb = combinations(arr, i + 1) for i in comb: sub.append(list(i)) for a in sub: z = 0 for b in a: z = z ^ b if z > max_xor: max_xor = z return max_xor N = int(input("Enter Length : ")) arr = [] for i in range(N): arr.append(int(input(f"Enter {i+1} Element : "))) if N < 3: print("Output :", max(arr)) else: print("Output :", fun(arr, N))
Q) You have been given a string S of length N. The given string is a binary string that consists of only 0’s and ‘1’s. Ugliness of a string is defined as the decimal number that this binary string represents.
Example:
- “101” represents 5.
- “0000” represents 0.
- “01010” represents 10.
There are two types of operations that can be performed on the given string.
- Swap any two characters by paying a cost of A coins.
- Flip any character by paying a cost of B coins
- flipping a character means converting a ‘1’to a ‘0’or converting a ‘0’ to a ‘1’.
Initially, you have been given coins equal to the value defined in CASH. Your task is to minimize the ugliness of the string by performing the above mentioned operations on it. Since the answer can be very large, return the answer modulo 10^9+7.
Note:
- You can perform an operation only if you have enough number of coins to perform it.
- After every operation the number of coins get deducted by the cost for that operation.
Input Format
- The first line contains an integer, N, denoting the number of character in the string
- The next line contains a string, S, denoting the the binary string
- The next line contains an integer, CASH, denoting the total number of coins present initially
- Next will contains an integer, A, denoting the cost to swap two characters.
- Then the next line contains an integer, B, denoting the cost to flip a character.
Constraints
- 1 <= N <= 10^5
- 1< len(S)<= 10^5
- 1<=CASH <=10^5
- 1<=A<=10^5
- 1<=B<=10^5
Sample Input 1 :
4
1111
7
1
2
Sample Output 1 :
1
Explanation:
3 flips can be used to create “0001” which represents 1.
Sample Input 2:
6
111011
7
1
3
Sample Output 2:
7
Explanation:
First swap 0 with the most significant 1, then use flip twice first on index one and then on index two “111011”=>”0111111″=>”001111″=>”000111″ the value represented is 7.
Sample Input 3:
6
111011
7
3
2
Sample Output 3:
3
Explanation:
Flip the 3 most significant characters to get “000011” : the value represented by this string is 3.N
EXAMPLE PROGRAMS
C++ PROGRAM
#include<bits/stdc++.h> using namespace std; string s; int n, cash, a, b; void swapf () { int i; for (int a = 0; a < s.length (); a++) if (s[a] == '1') { i = a; break; } int j = s.length () - 1; while (j > i) { if (cash < a) break; if (s[j] == '0') { if (s[i] == '0') i++; else { swap (s[i], s[j]); cash -= a; j--; } } else j--; } } void flipf () { int i; for (int a = 0; a < s.length (); a++) if (s[a] == '1') { i = a; break; } while (cash >= b) { if (i == s.length ()) break; if (s[i] == '1') { s[i] = '0'; i++; cash -= b; } } } int main () { cin >> n >> s >> cash >> a >> b; if (a < b) { swapf (); flipf (); } else { flipf (); swapf (); } cout << stoull (s, 0, 2); }
JAVA PROGRAM
import java.util.*; class Main { static String str; static int cash, n, a, b; static void swapf () { char s[] = str.toCharArray (); int i = 0; for (int a = 0; a < s.length; a++) if (s[a] == '1') { i = a; break; } int j = s.length - 1; while (j > i) { if (cash < a) break; if (s[j] == '0') { if (s[i] == '0') i++; else { char temp = s[i]; s[i] = s[j]; s[j] = temp; cash -= a; j--; } } else j--; } str = new String (s); } static void flipf () { char s[] = str.toCharArray (); int i = 0; for (int a = 0; a < s.length; a++) if (s[a] == '1') { i = a; break; } while (cash >= b) { if (i == s.length) break; if (s[i] == '1') { s[i] = '0'; i++; cash -= b; } } str = new String (s); } public static void main (String[]args) { Scanner sc = new Scanner (System.in); n = sc.nextInt (); str = sc.next (); cash = sc.nextInt (); a = sc.nextInt (); b = sc.nextInt (); if (a < b) { swapf (); flipf (); } else { flipf (); swapf (); } System.out.println (Integer.parseInt (str, 2)); } }
***BEST OFF LUCK***
We hope our article is informative. To stay ahead of the ever-increasing competition, you are strongly encouraged to download the previous year’s papers and start practicing. By solving these papers you will increase your speed and accuracy. For more information check Naukrimessenger.com website for exam patterns, syllabi, cut-off marks, answer keys, best books, and more to help you crack your exam preparation. You can also take advantage of amazing Job offers to improve your preparation volume by joining in Telegram Channel page!!!
Important Details |
---|