Infosys | InfytTq | Infosys Certification Exam Latest Coding Questions with Solutions
Infosys Certification Exam :
Importants: Here this blog we can discuss some previously asked coding question. Infosys Coding Questions and Answers.infosys coding questions 2022.infosys dse coding questions.Infosys programming questions for Freshers.infosys coding questions with answers 2020,2021,2022.infosys digital specialist engineer coding questions.Infosys Specialist Programmer coding questions and answers.
About :
First Round:- Qualifier Round Exam
Second Round:- Final Round Exam
Interview:- Systems Engineer Post Role.
Advantage Round:- For Higher Roles Like System Engineer Specialist & Power Programmer.
No of Questions:- 40
Negative Marking:- Yes 0.25 Per Wrong Questions
Total Marks:- 40 Marks Syllabus:- PYTHON/JAVA As You can choose Any One Language for the Whole Exam. DBMS, Aptitude (Same for Java/Python). Cut Off:- Not Disclosed by Infosys Team. Predictive Cut-Off:- 20-25 Correct Question.
Previously Asked Infosys Questions And Solutions
Question 1 : The Book Game
Note The book contains N Pages. Also you need to follow the order in which the page numbers are given in the array Initially your score is 0.
Input format:
First line : Two space separate integer N and K.
Next line : K space separate integer denoting the page numbers.
Output format :
Output the maximum score you can get print it modulo 10000000007.
Input Constraints
1 <= N <= 109
2 <= K <= 1o6
Sample Input 1
50 3
2 35 23
Output
30
Explanation : Last digit of all page numbers are 2 5 and 3
Initial score=0;
We add to score which now become 2. multiply with 5 making the score 10 finally multiply with 3 making the score 30 which is the maximum score.
Output 30 % (10 + 9 + 7) = 30.
import java.io.*; import java.util.*; public class TestClass { public static int getMaxScore(int k, int[] pages, int n){ long maxScore = 0; long mod = 1000000007; for(int i=0;i<k;i++) { long pn = pages[i]; long lastDigit = pn % 10L; if(lastDigit < 2) maxScore += lastDigit; else { if(maxScore == 0) maxScore = 1; maxScore *= lastDigit; } maxScore %= mod; } return (int)maxScore; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter wr = new PrintWriter(System.out); String[] input = br.readLine().split(" "); int n = Integer.parseInt(input[0]); int k = Integer.parseInt(input[1]); String[] arr_pages = br.readLine().split(" "); int[] pages = new int[k]; for(int i=0; i<arr_pages.length; i++) { pages[i] = Integer.parseInt(arr_pages[i]); } int ans = getMaxScore(k, pages, n); System.out.println(ans); wr.close(); br.close(); } }If you want solution of any questions, send me the question here codingsolution75 I will upload it soon.
Question 2 : Buy Items
the cost of the ith item.
You want to buy the maximum number of items possible using X amount of the money.
You can do the following operation at most once.
Pick any index i (1 <= i <= n) and change Ai to any positive integer.
Find the maximum number of items you can buy after applying this operation at most once.
Function description
Complete the maxItems function in the editor below it has the following parameter(s):
n Integer The size of array
A Integer Array The array A
X Integer The amount of money you have
Return The function must return Integer denoting the maximum.
Constraints
1 <= n <= 10^5
1 <= A[i] <= 10^5
1 <= X <= 10^9
Sample Test Cases
Input
4
1 2 3 4
5
Output
3
You can choose i = 2 and set A2 = 1. Then the array become [1,1,3,4,5]. You
can buy the fist there items at a total cost of 1 + 1 + 3 = 5.
Input
3
2 5 10
2
Output
1
Explanations
You can buy only the first item.
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Myclass { public static int maxItem(int n, int x , ArrayList<Integer> price){ Collections.sort(price); int count = 0; for(int p : price){ if(x >= p){ x = x - p; count++; }else if(x >= 1){ count++; break; }else{ break; } } return count; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<Integer> price = new ArrayList<Integer>(); for(int i=0; i<n; i++) { price.add(sc.nextInt()); } int x = sc.nextInt(); System.out.println(maxItem(n,x,price)); } }If you want solution of any questions, send me the question here codingsolution75 I will upload it soon.
Question 3 : Alternating Array
1. Create an array B of length N.
2. Add the first elements of A at the last potion of B.
3. Add the second elements of A at the first position of B.
4. Add the third elements of A at the second position of B.
5. Add the fourth elements of A at the second position of B.
6. Continue the above process till you have added all elements of A to B.
You are given an alternating array X having M elements. Let the original array of X elements called O.
Output the hash value (O[1]*10^1 + O[2]*10^2 + O[3]*10^3 + O[4]*10^4 + ....O[M]*10^5) modulo 10^9+7
Function description
Complete the solve function in the editor below It has the following parameter(s):
Name Type Description
M INTEGER The number of elements in the alteration array
X Integer The alternating array
Return The function must return an Integer denoting.
Constraints :
1 <= M <= 10^5
1 <= X[i] <= 10^9
Input format for debugging
The first line contains an integer M, denoting the number of elements of elements in X.
Each line i of the M subsequent lines (Where 0 <= i <= M ) contains an integer describing x[i].
Sample Test Case
Input
1
4
Output 40
Output Description
Original arrray is [4]
Answered is 4 * 10^1 = 40
Input
4
2 2 1 6
Output
21260
Output Description
6*10^1+2*10^2+1*10^3+2*10^4=21260
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Solution { public static int solve(int M, List<Integer> X) { long result =0; int[] B = new int[M]; if( M == 1) return X.get(0)*10; for(int i=0,j=M-1,p=0; i<j; i++,j--) { B[p++] = X.get(j); B[p++] = X.get(i); } for(int i=0,p=1; i<M; i++) { result += B[i]*(int)Math.pow(10, p++); } return (int)(result % ((int)Math.pow(10,9)+7)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int M = sc.nextInt(); List<Integer> list = new ArrayList<Integer>(); for(int i=0; i<M; i++) { list.add(sc.nextInt()); } System.out.println(solve(M,list)); } }If you want solution of any questions, send me the question here codingsolution75 I will upload it soon.
Question 4 : Palindrome Prefix
For example abba is a special palindrome with N=4 and K=2 ababa is not a special palindrome because aba is a palindrom its a prefix of ababa.
Task
Count the number of special palindromes.
Example
Assumptions
N = 3
k = 3
Approach
All possible special palindromes are aba, aca,bab,bcb,cac and cbc
Hence the answered is 6.
Input
3
3
Output
6
public class Main{ public static long prefix_Palindrom(int N,int K){ int M = 1000000000+9; long[] dp = new long[N+1]; dp[1] = K; for(int i=2; i<=N; i++){ if(i%2 == 1){ dp[i] = ((K * dp[i-1]) % M - dp[(i+1)/2] + M )%M; }else{ dp[i] = dp[i-1]; } } return dp[N]; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); System.out.println(prefix_Palindrom(N,K)); } }If you want solution of any questions, send me the question here codingsolution75 I will upload it soon.
Comments
Post a Comment
If you any doubts, please let me know Telegram Id: @Coding_Helperr
Instagram Id : codingsolution75