INFOSYS EXAM ANSWER
Telegram:- click here
About Infosys :
Infosys is a global leader in next-generation digital services and consulting. We enable clients in more than 50 countries to navigate their digital transformation. With over four decades of experience in managing the systems and workings of global enterprises, we expertly steer our clients through their digital journey. We do it by enabling the enterprise with an AI-powered core that helps prioritize the execution of change. We also empower the business with agile digital at scale to deliver unprecedented levels of performance and customer delight. Our always-on learning agenda drives their continuous improvement through building and transferring digital skills, expertise, and ideas from our innovation ecosystem.
Interview Qns:-
More update's Click here
Exam pattern:-
Infosys Syllabus 2021
Infosys has just changed their Infosys Syllabus 2021 for On and Off-campus Recruitment. For any company, we analyze each on-campus or off-campus drive to provide the most exact Infosys Online Test Pattern. As observed in Infosys Written Test Syllabus 2021, the questions are very tough for Infosys Test Pattern 2021. Below you will find the detailed Infosys Exam Pattern for the 2021 year.
Infosys Aptitude Test Syllabus
Logical Reasoning is the most difficult section asked in the Written Test Pattern for Infosys.
There are 5 sections in Infosys Online Test Paper
INFOSYS EXAM PATTERN :- Click here
Telegram:- click here
EXAM Answer's (9/1/22) morning slot
Coding Answer's
XOR elements
C++ language
Infosys
perfect_sum(arr, s, result) :
x = [0]*len(arr)
j = len(arr) - 1
while (s > 0) :
x[j] = s % 2
s = s // 2
j -= 1
sum = 0
for i in range(len(arr)) :
if (x[i] == 1) :
sum += arr[i]
if (sum == result) :
print("{",end="");
for i in range(len(arr)) :
if (x[i] == 1) :
print(arr[i],end= ", ");
print("}, ",end="")
def print_subset(arr, K) :
x = pow(2, len(arr))
for i in range(1, x):
perfect_sum(arr, i, K)
# Driver code
arr = [ ]
n = int(input("Enter length of array : "))
s=int(input("Enter sum : "))
for i in range(n):
ele=int(input("Enter element : "))
arr.append(ele)
print_subset(arr, s)
This one is for permutations question
Python
3)
class nodes
{
// Function to return the value of
// Binomial Coefficient C(n, k)
static int binomialCoeff(int n, int k)
{
if (k > n)
return 0;
int res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate the value of
// [n * (n - 1) *---* (n - k + 1)] /
// [k * (k - 1) * ... * 1]
for (int i = 0; i < k; ++i)
{
res *= (n - i);
res /= (i + 1);
}
return res;
}
// Driver Code
public static void main(String[] args)
{
int N = 5, M = 1;
int P = (N * (N - 1)) / 2;
System.out.println(binomialCoeff(P, M));
}
}
N No of Nodes Code ☑️
4)
Python
max value stored Code
John sum array
perfect_sum(arr, s, result) :
x = [0]*len(arr)
j = len(arr) - 1
while (s > 0) :
x[j] = s % 2
s = s // 2
j -= 1
sum = 0
for i in range(len(arr)) :
if (x[i] == 1) :
sum += arr[i]
if (sum == result) :
print("{",end="");
for i in range(len(arr)) :
if (x[i] == 1) :
print(arr[i],end= ", ");
print("}, ",end="")
def print_subset(arr, K) :
x = pow(2, len(arr))
for i in range(1, x):
perfect_sum(arr, i, K)
# Driver code
arr = [ ]
n = int(input("Enter length of array : "))
s=int(input("Enter sum : "))
for i in range(n):
ele=int(input("Enter element : "))
arr.append(ele)
print_subset(arr, s)
5)
class Main {
public static void main(String[] args) {
int[] numbers = {2, -9, 0, 5, 12, -25, 22, 9, 8, 12};
int sum = 0;
Double average;
// access all elements using for each loop
// add each element in sum
for (int number: numbers) {
sum += number;
}
// get the total number of elements
int arrayLength = numbers.length;
// calculate the average
// convert the average from int to double
average = ((double)sum / (double)arrayLength);
System.out.println("Sum = " + sum);
System.out.println("Average = " + average);
}
}
6)
Ali army code
Java
class Main {
public static void main(String[] args) {
int[] numbers = {2, -9, 0, 5, 12, -25, 22, 9, 8, 12};
int sum = 0;
Double average;
// access all elements using for each loop
// add each element in sum
for (int number: numbers) {
sum += number;
}
// get the total number of elements
int arrayLength = numbers.length;
// calculate the average
// convert the average from int to double
average = ((double)sum / (double)arrayLength);
System.out.println("Sum = " + sum);
System.out.println("Average = " + average);
}
}
7)
John has an array
n=int(input())
x=int(input())
y=int(input())
z=int(input())
a=[]
for i in range(n):
a.append(int(input()))
s=(x*1)+(y*2)+(z*3)
c=0
for i in a:
if i<=s:
c+=1
print(c)
8)
Chocolate factory code
Python
9)
10)
11)
Longest length Code
12)
Chocolate Factory Code
private static int minTime(int[] rate, int[] available) {
int n = rate.length;
int time = 0;
while (n > 0) {
int ind = findMax(rate);
if(time!=0){
available[ind] += (time * rate[ind]);
}
time += available[ind];
rate[ind] = Integer.MIN_VALUE;
n--;
}
return (arraySum(available) % 1000000007);
}
private static int findMax(int[] rate) {
int max = Integer.MIN_VALUE;
int maxIndex = -1;
for (int i = 0; i < rate.length; i++) {
if (rate[i] > max) {
max = rate[i];
maxIndex = i;
}
}
return maxIndex;
}
private static int arraySum(int[] available){
int sum = 0;
for(int i : available){
sum+=i;
}
return sum;
}
13
Ali cycle code
14)
array AR of size N
perfect_sum(arr, s, result) :
x = [0]*len(arr)
j = len(arr) - 1
while (s > 0) :
x[j] = s % 2
s = s // 2
j -= 1
sum = 0
for i in range(len(arr)) :
if (x[i] == 1) :
sum += arr[i]
if (sum == result) :
print("{",end="");
for i in range(len(arr)) :
if (x[i] == 1) :
print(arr[i],end= ", ");
print("}, ",end="")
def print_subset(arr, K) :
x = pow(2, len(arr))
for i in range(1, x):
perfect_sum(arr, i, K)
# Driver code
arr = [ ]
n = int(input("Enter length of array : "))
s=int(input("Enter sum : "))
for i in range(n):
ele=int(input("Enter element : "))
arr.append(ele)
print_subset(arr, s)
15)
Python
def check(a,n)
if n==1:
return 1
a.sort()
c=0
i=0
while(i<n-1):
if a[i+1]-a[i]==1:
i=i+2
c=c+1
else:
i=i+1
if c:
return c
else:
return 1
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
print(check(a,n)
16)
Python
Ali army
max_li=[]
def longest_subarray(arr, d):
(i, j, e) = (0, 1, 0)
for i in range(d - 1):
if arr[i] == arr[i + 1]:
j += 1
else:
j = 1
if e < j:
e = j
return e
temp=li.copy()
for each in li:
max_li.append(longest_subarray(temp, len(temp)))
temp=li.copy()
while(True):
try:
temp.remove(each)
except:
break
print(max(max_li))
17)
Python
John Code
n=int(input())
x=int(input())
y=int(input())
z=int(input())
a=[]
for i in range(n):
a.append(int(input()))
s=(x*1)+(y*2)+(z*3)
c=0
for i in a:
if i<=s:
c+=1
print(c)
18)
Whales code
Python
def check(a,n)
if n==1:
return 1
a.sort()
c=0
i=0
while(i<n-1):
if a[i+1]-a[i]==1:
i=i+2
c=c+1
else:
i=i+1
if c:
return c
else:
return 1
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
print(check(a,n))
Infosys Exam Answer's afternoon slot (9/1/22)
1)
def check(a,n)
if n==1:
return 1
a.sort()
c=0
i=0
while(i<n-1):
if a[i+1]-a[i]==1:
i=i+2
c=c+1
else:
i=i+1
if c:
return c
else:
return 1
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
print(check(a,n))
array one
Python
2)
Max of binary South
Python
3)
4)
n=int(input())
m=int(input())
s=input()
t=input()
def subString(s,n):
c=0
for i in range(n):
for len in range(i+1,n+1):
a=s[i: len]
c+=1
return c-2
if s==t:
print(1)
else:
if t in s:
print(subString(s,n))
else:
print(0)
Python
5)
Maximum possibility of unique digits in k divided subarrray of given arraylist
Java code
INFOSYS EXAM ANSWER'S (10/1/22)
Angry professor
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int t,count=0;
scanf("%d",&t);
for(int a0 = 0; a0 < t; a0++){
count=0;
int n;
int k;
scanf("%d %d",&n,&k);
int a[n];
for(int a_i = 0; a_i < n; a_i++){
scanf("%d",&a[a_i]);
}
for(int a_i = 0; a_i < n; a_i++){
if(a[a_i]<=0)
count++;
}
if(count<k)
printf("YES\n");
else
printf("NO\n");
//count=0;
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int t,count=0;
scanf("%d",&t);
for(int a0 = 0; a0 < t; a0++){
count=0;
int n;
int k;
scanf("%d %d",&n,&k);
int a[n];
for(int a_i = 0; a_i < n; a_i++){
scanf("%d",&a[a_i]);
}
for(int a_i = 0; a_i < n; a_i++){
if(a[a_i]<=0)
count++;
}
if(count<k)
printf("YES\n");
else
printf("NO\n");
//count=0;
}
return 0;
}
C language & python
Permutations code
South Indian kingdom
Java
import java.util.*;
class abc {
public static void main(String[] args) {
List<String> chola = new ArrayList<String>();
List<String> chera = new ArrayList<String>();
List<String> pallava = new ArrayList<String>();
List<String> pandya = new ArrayList<String>();
List<String> renounce = new ArrayList<String>();
Scanner kb = new Scanner(System.in);
int q = kb.nextInt();
for (int i=0; i <q; i++)
{
String name = kb.next();
int x = kb.nextInt();
int y = kb.nextInt();
if (x == 0 || y == 0)
renounce.add(name);
else if(x >0 && y >0)
chola.add(name);
else if(x >0 && y <0)
chera.add(name);
else if(x <0 && y <0)
pallava.add(name);
else if(x <0 && y >0)
pandya.add(name);
}
System.out.println("chola");
System.out.println(chola);
System.out.println("chera");
System.out.println(chera);
System.out.println("pallava");
System.out.println(pallava);
System.out.println("pandya");
System.out.println(pandya);
System.out.println("renounce");
System.out.println(renounce);
}
}
Maximize number of groups formed with size not smaller than its largest element
C++
Output :- 2
// C++ program to find minimum time
// required to produce m items.
#include<bits/stdc++.h>
using namespace std;
// Return the minimum time required to
// produce m items with given machines.
int minTime(int arr[], int n, int m)
{
// Initialize time, items equal to 0.
int t = 0;
while (1)
{
int items = 0;
// Calculating items at each second
for (int i = 0; i < n; i++)
items += (t / arr[i]);
// If items equal to m return time.
if (items >= m)
return t;
t++; // Increment time
}
}
// allcoding1
int main()
{
int arr[] = { 1, 2, 3 };
int n = sizeof(arr)/sizeof(arr[0]);
int m = 11;
cout << minTime(arr, n, m) << endl;
return 0;
}
Minimum time
C language
Red And White Flower
Python Program
28/1/22 EXAM Answer's
Whales code
Python
def check(a,n)
if n==1:
return 1
a.sort()
c=0
i=0
while(i<n-1):
if a[i+1]-a[i]==1:
i=i+2
c=c+1
else:
i=i+1
if c:
return c
else:
return 1
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
print(check(a,n))
C++
/*
* This C++ program tells if there exists a pair in array whose sum results in x.
*/
#include <iostream>
using namespace std;
// Function to find and print pair
bool chkPair(int A[], int size, int x) {
for (int i = 0; i < (size - 1); i++) {
for (int j = (i + 1); j < size; j++) {
if (A[i] + A[j] == x) {
cout << "Pair with a given sum " << x << " is (" << A[i] << ", " << A[j] << ")"
<< endl;
return 1;
}
}
}
return 0;
}
int main(void) {
int A[] = {0, -1, 2, -3, 1};
int x = -2;
int size = sizeof(A) / sizeof(A[0]);
if (chkPair(A, size, x)) {
cout << "Valid pair exists" << endl;
}
else {
cout << "No valid pair exists for " << x << endl;
}
return 0;
}
def minOps(A, B):
m = len(A)
n = len(B)
# This part checks whether conversion is possible or not
if n != m:
return -1
count = [0] * 256
for i in range(n): # count characters in A
count[ord(B[i])] += 1
for i in range(n): # subtract count for every char in B
count[ord(A[i])] -= 1
for i in range(256): # Check if all counts become 0
if count[i]:
return -1
# This part calculates the number of operations required
res = 0
i = n-1
j = n-1
while i >= 0:
# if there is a mismatch, then keep incrementing
# result 'res' until B[j] is not found in A[0..i]
while i>= 0 and A[i] != B[j]:
i -= 1
res += 1
# if A[i] and B[j] match
if i >= 0:
i -= 1
j -= 1
return res
# Driver program
A = "EACBD"
B = "EABCD"
print ("Minimum number of operations required is " + str(minOps(A,B)))
# This code is contributed
#Minimum number of operations required
C++ program to count distinct elements
// in a given array
#include <iostream>
using namespace std;
int countDistinct(int arr[], int n)
{
int res = 1;
// Pick all elements one by one
for (int i = 1; i < n; i++) {
int j = 0;
for (j = 0; j < i; j++)
if (arr[i] == arr[j])
break;
// If not printed earlier, then print it
if (i == j)
res++;
}
return res;
}
// Driver program to test above function
int main()
{
int arr[] = { 12, 10, 9, 45, 2, 10, 10, 45 };
int n = sizeof(arr) / sizeof(arr[0]);
cout << countDistinct(arr, n);
return 0;
}
Distinct elements in array code
1. Jolly num code
// Program for Jolly Jumper Sequence
#include<bits/stdc++.h>
using namespace std;
// Function to check whether given sequence is
// Jolly Jumper or not
bool isJolly(int a[], int n)
{
// Boolean vector to diffSet set of differences.
// The vector is initialized as false.
vector<bool> diffSet(n, false);
// Traverse all array elements
for (int i=0; i < n-1 ; i++)
{
// Find absolute difference between current two
int d = abs(a[i]-a[i+1]);
// If difference is out of range or repeated,
// return false.
if (d == 0 d > n-1 diffSet[d] == true)
return false;
// Set presence of d in set.
diffSet[d] = true;
}
return true;
}
// Driver Code
int main()
{
int a[] = {11, 7, 4, 2, 1, 6};
int n = sizeof(a)/ sizeof(a[0]);
isJolly(a, n)? cout << "Yes" : cout << "No";
return 0;
}
Jolly num code
C
INFOSYS EXAM ANS (23/4/22)