Infosys 22nd January 2023 Both Slots 10 AM and 3 PM Live Coding Question and Solution | Refresh Every 5 Seconds for New Updates | SP | DSE Hiring | Page Vanish After the Exam
Infosys 22nd January 2023 Both Slots 10 AM and 3 PM Live Coding Question and Answers | Refresh Every 5 Seconds for New Updates | SP | DSE Hiring | Page Vanish After the Exam:
Infosys Officially Announced Hiring Freshers Engineering Graduates as Below Mentioned positions.Infosys Hiring for Specialist Programmer and Digital Specialist Engineer Role in PAN, India,India Software, and Services For the full time. Infosys company is going to recruit candidates for graduates off-campus. The candidates who have completed B.E/ B.Tech/ M.E/ M.Tech/ MCA/ M.Scin Any Specialization Graduates Engineering Graduates degree in any Streams/Branch Pass out in the Year 2022/ 2021/ 2020 Batch Eligible Only. batches are Eligible to apply.
In this article, you can easily find the Infosys address, date of interview, eligibility details, interview syllabus, selection process, application link, and application procedure details explanation is given below.
In this article, you will get to know this drive, and also you can prefer a video that I created for your better understanding firstly understand the few points which I discussed in this video before applying.
For more such Latest new off-campus drives and for many years, internships, and free courses are updated on our website.
Infosys 2022 Recruitment Drive For Freshers – Any Batch:
Company Name: Infosys.
Experience: Freshers/Any
Job Title: Specialist Programmer and Digital Specialist Engineer
Infosys Limited is an Indian multinational information technology company that provides business consulting, information technology and outsourcing services. The company was founded in Pune and is headquartered in Bangalore. Wikipedia
Get The Future You Want | www.Infosys.com
Infosys 22nd January 2023 Both Slots 3 PM Live Coding Question and Solution Refresh Every 5 Seconds for New Question or else use search Option 'Control F':
# Python 3 program to find subsequence
# of size k with maximum possible GCD.
import math
# function to find GCD of sub sequence
# of size k with max GCD in the array
def findMaxGCD(arr, n, k):
# Computing highest element
high = max(arr)
# Array to store the count of
# divisors i.e. Potential GCDs
divisors = [0] * (high + 1)
# Iterating over every element
for i in range(n) :
# Calculating all the divisors
for j in range(1, int(math.sqrt(arr[i])) + 1):
# Divisor found
if (arr[i] % j == 0) :
# Incrementing count for divisor
divisors[j] += 1
# Element/divisor is also a divisor
# Checking if both divisors are
# not same
if (j != arr[i] // j):
divisors[arr[i] // j] += 1
# Checking the highest potential GCD
for i in range(high, 0, -1):
# If this divisor can divide at least k
# numbers, it is a GCD of at least one
# sub sequence of size k
if (divisors[i] >= k):
return i
# Driver code
if name == "main":
# Array in which sub sequence with size
# k with max GCD is to be found
arr = [ 1, 2, 4, 8, 8, 12 ]
k = 3
n = len(arr)
print(findMaxGCD(arr, n, k))
# This code is contributed by ita_c
______
3PM Slots Ans
____________________________-
3PM Slots Ans
___________________
3PM Slots Ans
____________________
public static int beautyNumber(int N, long C, int[] A) {
int count = 0;
HashMap<String, Integer> subArrays = new HashMap<>();
for (int i = 0; i < N; i++) {
int left = 0, right = 0, sum = 0;
while (sum <= A[i]) {
sum += U[right];
if (sum == A[i]) {
String subArray = Arrays.toString(Arrays.copyOfRange(U, left, right + 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)
____________________
Find all subarray index ranges in given Array with set bit sum
equal to X
Given an array arr (1-based indexing) of length N and an integer
X, the task is to find and print all index ranges having a set bit sum equal to
X in the array.
Examples:
Input: A[] = {1 4 3 5 7}, X = 4
Output: (1, 3), (3, 4)
Explanation: In the above array subarray having set bit sum
equal to X (= 4).
Starting from index 1 to 3. {1 4 3} = (001) + (100) + (011) = 4 and
other one is from 3 to 4 {3, 5} = (011) + (101) = 4.
Input: arr[] = {5, 3, 0,
4, 10}, X = 7
Output: (1 5)
Solution :
defcountSetBit(arr, n):
c =0
fori inrange(n):
x =arr[i]
while(x):
l =x %10
if(x & 1):
c +=1
x =x //2
arr[i] =c
c =0
defPrintIndex(arr, N, X, v):
i,j,currSum =0,0,arr[0]
while(j < N andi < N):
if(currSum ==X):
v.append(i +1)
v.append(j +1)
j +=1
if(j<N):
currSum +=arr[j]
elif(currSum < X):
j +=1
if(j<N):
currSum +=arr[j]
else:
currSum -=arr[i]
i +=1
# Driver code
v =[1, 4, 3, 5, 7]
X =4
N =len(v)
countSetBit(v, N)
ans =[]
PrintIndex(v, N, X, ans)
fori inrange(0,len(ans) -1,2):
print(f"({ans[i]} {ans[i +
1]})",end=" ")
______________________________
Soluion 1:
def findXor(arr,n):
#
Calculate xor of
#
all the elements
xoR = 0;
for i in range (0, n ) :
xoR = xoR ^ arr[i]
#
Return twice of
#
xor value
return xoR * 2
# Driver code
arr = [ 1, 5, 6 ]
n = len(arr)
print(findXor(arr, n))
Solution 2:
def findXorSum(arr, n):
#
variable to store the final Sum
Sum = 0
#
multiplier
mul = 1
for i in range(30):
c_odd = 0
odd = 0
for j in range(n):
if ((arr[j] & (1 << i)) > 0):
odd = (~odd)
if (odd):
c_odd += 1
for j in range(n):
Sum += (mul * c_odd)
if ((arr[j] & (1 << i)) > 0):
c_odd = (n - j - c_odd)
mul *= 2
return Sum
arr = [3, 8, 13]
n =
len(arr)
print(findXorSum(arr, n))
____________________
#include<iostream>
#include<unordered_map>
#include<string>
#include<math.h>
using namespace std;
int ans(string s){
unordered_map map;
for(int i =0; i map[s[i]]){
} }
return val; }
int main() {
string s;
cin>>s;
cout<< ans(s);
return 0; }
val = map[s[i]];
key = map[s[i]];
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)
Python
____3PM Slots Ans ___________
__3PM Slots Ans
_______
public class XOR {
public static int findMaxOverlappingSegments(int[] A) {
1.You have an array A of length N and two empty baskets
2.You are given an array Arr of size N
3.You have an weighted tree, rooted at vertex 1 that consists of N vertices and N-1 undirected edges it is given that we define path benefit as the minimum weight in the path
_______3PM Slots Ans
______
Submask
Empty baskets
Non empty sub set
Smallest lexicographical array
Minimum poosibble cost
10^9+7
1)You are given an array A with permutation P with length N.
2) find total number of ways to participation A.
3) find the total number of elements in good term.
1. Find the lexicographical array possible after swapping
2.find the sum of F(i) for all where (1<=i<=N) and (I!=s). Since the answer might be large return it modulo 10^9+7
______3PM Slots Ans
________
import itertools
def permutation_cost(s):
# Get all possible permutations of the first 20 lowercase English letters
permutations = list(itertools.permutations(s))
# Set initial minimum cost to a large number
min_cost = float('inf')
for perm in permutations:
cost = 0
# Iterate through the permutation
for i in range(len(perm) - 1):
# If the next letter appears before the current letter in the permutation, add 1 to the cost
if perm[i] > perm[i + 1]:
cost += 1
# Update minimum cost if necessary
min_cost = min(min_cost, cost)
return min_cost
s = 'abcdefghijklmnopqrstuvwxyz'[:20]
print(permutation_cost(s))import itertools
def permutation_cost(s):
# Get all possible permutations of the first 20 lowercase English letters
permutations = list(itertools.permutations(s))
# Set initial minimum cost to a large number
min_cost = float('inf')
for perm in permutations:
cost = 0
# Iterate through the permutation
for i in range(len(perm) - 1):
# If the next letter appears before the current letter in the permutation, add 1 to the cost
if perm[i] > perm[i + 1]:
cost += 1
# Update minimum cost if necessary
min_cost = min(min_cost, cost)
return min_cost
s = 'abcdefghijklmnopqrstuvwxyz'[:20]
print(permutation_cost(s))
_________3PM Slots Ans
________
3PM Slots Ans
____________
3PM Slots Ans
___________
2 baskets array solution!
_________
_________
Smallest lexicographical array Minimum possible cost
_______
given an array A of size N.
You are allowed to choose at most one pair of elements such that distance (defined as the difference of their indices) is at most K and swap them.
Find the smallest lexicographical array possible after
Notes:
An array x is lexicographically smaller than an array y if there exists an index i such that xi <y i1 and x_{j} = y_{j} for all 0 <= j < i . Less formally, at the first index i in which they differ xi < yi
Input Formats@gman
The First-line contains Integers N Ea an integer, N, denoting the line i of the N subsequent lines (where describing A[i]. of elements in A. N) contains an integer
The next line contains an integer, K, denoting the upper bound on distance of index.
Constraints
Here as all the array values are equal swapping will not change the final result,
Here A=[5,4,3,2,11 K we can swap elements at index 0 and index 3 which makes A= [2,4,3,5,1].
Here A=[2,1,1,1,1] K we can swap elements at index 0 and index 3 chat which makes A= [1.1.1.2.11
bool swapped = false;
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j <= min(i + K, N - 1); j++) {
if (A[i] > A[j]) {
swap(A[i], A[j]);
swapped = true;
break;
}
}
if (swapped) break;
}
if (!swapped) return A;
else return A;
C++
__________
Longest Subsquence
Python
_______
________
_________
_______
___________
You are given a rooted tree of N vertices and an array A of N integers A[i] is the parent of the vertex (i+1 or 0 if the vertex (i+1) is the root.
For each vertex V from 1 to N, the answer K is the total number of subsets of vertices with the LCA (lowest common ancestor) equal to V Since the of K can be large calculate it modulo 10 ^ 9 + 7
Let there be an integer array Res where Res[i] contains the answer for (I + 1)th vertex, Find the array Res
Notes:
• The lowest common ancestor (LCA) is defined for X nodes A1, A2,.... Ax as the lowest node in the tree that has all A1 A2..... Ax as descendants (where we allow a node to be a descendant of itself)
Input Formate
The first line contains an integer N denoting the number of elements in A
Each line 1 of the N subsequent lines (where 0<=i<N) contains an integer
describing All It is given that A[i] denotes the parent of the vertex (i+1) or 0
You are given an f length N and an array B of length M.
You need to find the longest possible sub-sequence (not necessarily of consecutive elements) of A such that it does not have amay B as a sub-arrey elements).
Find the length of the such sub-sequence.
A subsequence is a sequence that can be derived sequence by deleting some or no elements without changing the order of the • A subarray is a contiguous part of an array and maintains a relative ordering of elements.
Input Format
The first line contains an integer, N, denoting the size of array A.
Each line i of the N subsequent lines (where 0 ≤i≤N) contains an I integer describing A[i]
The next line contains an integer, M, denoting the size of array B.
Each line i of the M subsequent lines (where 0 ≤i≤ M) contains a an integer describing B[i].
Constraints
1 <= N <= 500
1 <= A[i] <= 100
1 <= M <= N
1 <= B[i] <= 100
N=4 A= [4, 4, 4. 4) M= 2 B= [4, 4] if you take any sub-sequence longer than 1, then array B will be the subarray of the chosen subsequence, so the answer here is 1.
N=5A [1, 2, 3,4,M =2 B=[6, 7] Since there is no common element between A and B, the longest subsequence answer is 5. we can choose is complete A hence the answer is 5
____
N=5A= [1, 2, 3, 4, 5] M = 3 B = [1, 2, 3] we can not choose complete A since B will be a subarray of that so choose [1,2,4,5] as a subsequence and B is not a subarray of chosen subsequence hence the answer is 4.
func getMax (N int32, A []int32, M int32, B []int32) int32 { write your code here}
____________
def minJumps(arr, n):
jumps = [0 for i in range(n)]
if (n == 0) or (arr[0] == 0):
return float('inf')
jumps[0] = 0
for i in range(1, n):
jumps[i] = float('inf')
for j in range(i):
if (i <= j + arr[j]) and (jumps[j] != float('inf')):
jumps[i] = min(jumps[i], jumps[j] + 1)
break
return jumps[n-1]
arr = [1,1,1,2,4]
n = len(arr)
print('Minimum number of jumps to reach end is', minJumps(arr, n))