Infosys Off Campus Coding Question and Answers 2025 | Infosys Interview Coding Questions | Infosys Off Campus Interview Questions and Answers
Infosys Off Campus Coding Question and Answers 2025: The Coding Questions and Answers is very important in the IT Sector and Private Job Sector. Now days candidates are mostly interested in the off-Campus drive and private jobs. Eagerly prepare for the Coding Interview, Assessment Test, and attend the many samples online test for Private jobs. Following of the hiring, Infosys issued the Off Campus Drive for eligible and capable candidates. The Infosys Off Campus Drive selection process coding test, technical test etc., The Coding Interview round will be asked many questions through sample of C, C++, Java, Python Programming Languages. Thoroughly prepare for the Infosys Off campus Coding Interview. Here we uploaded major common Infosys Off campus Coding Questions and Infosys Coding Interview Questions. Applicants must prepare Infosys Off Campus Coding Questions and Answers.
You have spent a time to solve the Infosys Off Campus Coding Questions while using this page. The Very Infosys Coding Interview questions consist of each programming languages. So, candidates prepare all programming languages on one by one. Variety of the sample Infosys Off campus Coding Interview Questions makes confidence to attend the Infosys Off Campus drive. Once you have selected in the Infosys coding Interview round, you will be move on further selection process. The coding interview round is main part of the Infosys Hiring. Candidates focused to prepare Infosys Off Campus Drive Coding Questions and Infosys Coding Interview Questions and Answers.
Infosys Off Campus Interview Coding Questions 2024
Company Name | Infosys |
Category | Coding Questions and Answers |
Infosys Coding Interview and Answers
Question 1: While playing an RPG game, you were assigned to complete one of the hardest quests in this game. There are n monsters you’ll need to defeat in this quest. Each monster i is described with two integer numbers – poweri and bonusi. To defeat this monster, you’ll need at least poweri experience points. If you try fighting this monster without having enough experience points, you lose immediately. You will also gain bonusi experience points if you defeat this monster. You can defeat monsters in any order.
The quest turned out to be very hard – you try to defeat the monsters but keep losing repeatedly. Your friend told you that this quest is impossible to complete. Knowing that, you’re interested, what is the maximum possible number of monsters you can defeat?
Input:
- The first line contains an integer, n, denoting the number of monsters. The next line contains an integer, e, denoting your initial experience.
- Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer, poweri, which represents power of the corresponding monster.
- Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer, bonusi, which represents bonus for defeating the corresponding monster.
Input | Output | Output Description |
---|---|---|
2 123 78 130 10 0 |
2 |
|
3 100 101 100 304 100 1 524 |
2 |
|
JAVA
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int exp = s.nextInt(); int monst[] = new int[n]; int bonus[] = new int[n]; for (int i = 0; i < n; i++) { monst[i] = s.nextInt(); } for (int i = 0; i < n; i++) { bonus[i] = s.nextInt(); } class Monster { private final int power, bonus; public Monster(int power, int bonus){ this.power = power; this.bonus = bonus; } } Monster[] monsters = new Monster[n]; for(int i = 0; i < n; i++) monsters[i] = new Monster(monst[i], bonus[i]); Arrays.sort(monsters, Comparator.comparingInt(m -> m.power)); int count = 0; for(Monster m: monsters){ if(exp < m.power) break; exp += m.bonus; ++count; } System.out.println(count); } }
PHYTHON
n = int(input()) lev = int(input()) p = [] b = [] a = [] ans = 0 for i in range(n): p.append(int(input())) for j in range(n): b.append(int(input())) for k in range(n): a.append([p[k], b[k]]) a.sort() for z in a: if z[0] > lev: break lev += z[1] ans += 1 print(ans)
C++
#include<iostream> #include<map>
Question 2: You have an array A of N integers A1 A2 .. An. Find the longest increasing subsequence Ai1 Ai2 .. Ak
(1 <= k <= N) that satisfies the following condition:
For every adjacent pair of numbers of the chosen subsequence Ai[x] and Ai[x+1] (1 < x < k), the expression( Ai[x] & Ai[x+1] ) * 2 < ( Ai[x] | Ai[x+1] ) is true
Note: ‘&’ is the bitwise AND operation, ‘ | ‘ is the bit-wise OR operation
Input:
- 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.
Sample cases:
Input | Output | Output Description |
---|---|---|
5 15 6 5 12 1 |
2 | One possible subsequence is: 5 12 |
6 9 17 2 15 5 2 |
2 | One possible subsequence is: 2 15 |
7 17 16 12 2 8 17 17 |
3 | One possible subsequence is: 2 8 17 |
JAVA
class Main { public static int LIS(int[] arr, int i, int n, int prev) { if (i == n) { return 0; } int excl = LIS(arr, i + 1, n, prev); int incl = 0; if (arr[i] > prev) { incl = 1 + LIS(arr, i + 1, n, arr[i]); } return Integer.max(incl, excl); } public static void main(String[] args) { int[] arr = { 15, 6, 5, 12, 1 }; System.out.print("The length of the LIS is " + LIS(arr, 0, arr.length, Integer.MIN_VALUE)); } }
PHYTHON
def sub(arr, i, n, prev=0): if i == n: return 0 a = sub(arr, i + 1, n, prev) b = 0 if arr[i] > prev: b = 1 + sub(arr, i + 1, n, arr[i]) return max(b, a) n = int(input()) arr = [] for i in range(n): arr.append(int(input())) print("Length of Bitwise subsequence will be", sub(arr, 0, len(arr)))
C++
PHYTHON
#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); }
Question 4: 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.
JAVA
import java.util.*; class Main { public static void main (String[]args) { final int N = 120, M = 1 << 20; int dp[] = new int[M]; char res[] = new char[M]; 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 (); for (int i = 1; i < M; i++) dp[i] = Integer.MAX_VALUE; 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; System.out.println (j); } }
PHYTHON
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))
C++
JAVA
import java.util.*; class Main { public static boolean convertBase (int m, int base) { int rem = m % base; m = m / base; while (m >= base && (m % base == rem)) m = m / base; if (m == rem) return true; return false; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int m = sc.nextInt (); int base = 2; while (convertBase (m, base) != true) base++; System.out.println (base); } }
PHYTHON
def convertBase(m, base): rem = m % base m = m // base while m >= base and (m % base == rem): m = m // base if m == rem: return True return False m = int(input()) base = 2 while not convertBase(m, base): base = base + 1 print(base)
C++
#include<bits/stdc++.h> using namespace std; bool converted (int M, int base) { int rem = M % base; M /= base; while (M >= base) { if (M % base != rem) return 0; M /= base; } if (M == rem) return 1; return 0; } int main () { int M; cin >> M; int base = 2; while (converted (M, base) != 1) { base++; } cout << base; return 0; }
While using this page to get an Infosys Off Campus Coding Questions with Answers and Infosys Coding Interview Coding Questions. Kindly watch dailyrecruitment.in site.
INSTAGRAM LINK | FOLLOW NOW >> |
JOB ALERT ON TELEGRAM | JOIN NOW>> |
Govt Jobs by Qualifications
Education & Vacancies | Salary | Apply Link |
---|---|---|
12th Pass Govt Jobs - 18,000+ Vacancies | Rs. 5,200 - 92,300 | Apply Now |
ITI Pass Jobs - 3,500 Vacancies | Rs. 5,200 - 35,000 | Apply Now |
Any Graduate Jobs - 19,100 Vacancies | Rs. 5,200 - 92,300 | Apply Now |
Central Govt Jobs | Rs. 5,200 - 17,000 | Apply Now |
Bank Jobs - 1,000 Vacancies | Rs. 5,200 - 29,200 | Apply Now |
Diploma Jobs - 9,300 Vacancies | Rs. 5,200 - 35,000 | Apply Now |
BTech/BE Jobs - 18,000 Vacancies | Rs. 15,000 - 1,00,000 | Apply Now |
Data Entry Jobs - 1,300 Vacancies | Rs. 5,200 - 29,200 | Apply Now |
Private Jobs | Rs. 10,000 - 67,700 | Apply Now |