**Infosys SP and DSE Coding Sample Questions & Answers 2024 | Infosys SP and DSE Coding Model Questions | Infosys SP and DSE Coding Questions For Freshers | Infosys SP Coding Questions | Infosys DSE Coding Questions**

**Infosys SP and DSE Coding Sample Questions & Answers 2024: **The Infosys SP and DSE coding test is medium complexity, meaning that while passing it is not impossible, it is also not very simple. If you practiced some of the code questions from the previous year’s examination, you would undoubtedly have an advantage in the upcoming Infosys SP and DSE coding exams. Let’s look at a few test patterns, Infosys SP and DSE MCQ Questions and Answers/ Infosys SP and DSE Coding MCQ Questions in Python, C, C++, Java, and Python code problems and their fixes. In the below section, you can find the Infosys SP and DSE Exam Questions and Answers/Infosys SP and DSE **Coding Questions** & Answers 2023

Previous recruiting campaigns’ coding examinations placed a strong focus on arrays and other fundamental programming principles. One can easily pass the first round and even the ones after that if they prepare adequately. You must select a language that you are comfortable with, such as C, C++, Java, or even Python, in order to complete the coding tasks. More details like Infosys SP and DSE Coding Questions and Answers, Infosys SP and DSE Model Coding Questions & Answers, Infosys SP and DSE Coding Questions & Answers in Java, Infosys SP and DSE Coding Questions & Answers in Java, etc. available on its website

**Infosys SP and DSE Coding Test Scheme 2024**

- Three hours are allotted for answering the three questions in the coding round.
- Every question has a certain degree of difficulty.
- An easy algorithmic, aptitude and data structure problem exists.
- A medium-level issue is among them, and it stems from algorithmic greed.
- One is based on dynamic programming and is a hard difficulty level.

### Infosys SP and DSE Coding Test Pattern 2024/Infosys SP and DSE Coding Test Syllabus 2024

Total Questions | Marks Allocated |
---|---|

Question 1 | 20 Marks |

Question 2 | 30 Marks |

Question 3 | 50 Marks |

Total |
100 Marks |

**Infosys SP and DSE Coding Sample Questions & Answers For Freshers**

**Q)** **Write a program to find the difference between the elements at odd index and even index.**

**Note** : You are expected to write code in the **findDifference** function only which receive the first parameter as the numbers of items in the array and second parameter as the array itself. You are not required to take the input from the console.

**Example**

Finding the maximum difference between adjacent items of a list of 5 numbers

**Input
**input 1 : 7

input 2 : 10 20 30 40 50 60 70

**Output
**40

**Explanation
**The first parameter 7 is the size of the array. Sum of element at even index of array is 10 + 30 + 50 + 70 = 160 and sum of elements at odd index of array is 20 + 40 + 60 = 120. The difference between both is 40

**Here is the code:**

#include <stdio.h> int findDifference(int n, int arr[]) { int odd=0, even=0; for(int i=0; i<n; i++) { if(i%2==0) { even = even + arr[i]; } else { odd = odd + arr[i]; } } return even-odd; } int main() { int n; scanf("%d",&n); int array[n]; for(int i=0; i<n; i++) { scanf("%d",&array[i]); } int result = findDifference(n, array); printf("%d",result); return 0; }

**Q)** **Write a program to calculate and return the sum of absolute difference between the adjacent number in an array of positive integers from the position entered by the user.**

**Note** : You are expected to write code in the **findTotalSum **function only which receive three positional arguments:

1st : number of elements in the array

2nd : array

3rd : position from where the sum is to be calculated

**Example**

**Input
**input 1 : 7

input 2 : 11 22 12 24 13 26 14

input 3 : 5

**Output
**25

**Explanation**

The first parameter 7 is the size of the array. Next is an array of integers and input 5 is the position from where you have to calculate the Total Sum. The output is 25 as per calculation below.

| 26-13 | = 13

| 14-26 | = 12

Total Sum = 13 + 12 = 25

**Here is the code:**

#include <stdio.h> #include <stdlib.h> int findTotalSum(int n, int arr[], int start) { int difference, sum=0; for(int i=start-1; i<n-1; i++) { difference = abs(arr[i]-arr[i+1]); sum = sum + difference; } return sum; } int main() { int n; int start; scanf("%d",&n); int array[n]; for(int i=0; i<n; i++) { scanf("%d",&array[i]); } scanf("%d",&start); int result = findTotalSum(n, array, start); printf("\n%d",result); return 0; }

**Q)** **Write a program to return the difference between the count of odd numbers and even numbers**.

You are expected to write code in the **countOddEvenDifference **function only which will receive the first parameter as the number of items in the array and second parameter as the array itself. you are not required to take input from the console.

**Example
**Finding the difference between the count of odd and even numbers from a list of 5 number

**Input
**input 1 : 8

input 2 : 10 20 30 40 55 66 77 83

**Output
**-2

**Explanation
**The first paramter (8) is the szie of the array. Next is an array of integers. The calculation of difference between count sum of odd and even numbers is as follows:

**3 (count of odd numbers) – 5 (count of even numbers) = -2**

**Here is the code:**

#include <stdio.h> int countOddEvenDifference(int n, int arr[]) { int odd = 0, even = 0; for(int i=0; i<n; i++) { if(arr[i]%2==0) { even = even+1; } else { odd = odd+1; } } return odd - even; } int main() { int n; scanf("%d",&n); int array[n]; for(int i=0; i<n; i++) { scanf("%d",&array[i]); } int result = countOddEvenDifference(n, array); printf("%d",result); return 0; }

**Infosys SP and DSE Coding Sample Questions & Answers**

**Question) **Rohan and his team are participating in the Treasure Hunt event of college in which in each step they have to solve one problem to get a clue about the Treasure location. Rohan’s team has performed very well and reached the final step where they have to provide a code of a problem to get a final clue about treasure .

Given a string s, they need to find the longest palindromic subsequence’s length in s.

A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

The string contains only lowercase letters.

Write a program to help Rohan’s team that takes in input as String x and returns the length of the longest palindromic subsequence of x.

**Input Specification:**

**input1**: string input

**Output Specification:**

Return the length of the longest palindromic subsequence

**Example 1:**

**Input:** s = “bbbab”

**Output:** 4

**Explanation:** One possible longest palindromic subsequence is “bbbb”.

**Example 2:**

**Input:** s = “cbbd”

**Output:** 2

**Explanation:** One possible longest palindromic subsequence is “bb”.

**C++ PROGRAM**

#include<iostream> #include<cstring> using namespace std; int max (int x, int y) { return (x > y)? x : y; } int lps(char *str) { int n = strlen(str); int i, j, cl; int L[n][n]; for (i = 0; i < n; i++) L[i][i] = 1; for (cl = 2; cl <= n; cl++) { for (i = 0; i < n-cl+1; i++) { j = i + cl-1; if (str[i] == str[j] && cl == 2) L[i][j] = 2; else if (str[i] == str[j]) L[i][j] = L[i+1][j-1] + 2; else L[i][j] = max(L[i][j-1], L[i+1][j]); } } return L[0][n-1]; } int main() { char seq[20]; cin >> seq; int n = strlen(seq); printf("%d", lps(seq)); getchar(); return 0; }

**JAVA PROGRAM**

import java.util.*; public class Main { static int max (int x, int y) { return (x > y)? x : y; } static int lps(String seq) { int n = seq.length(); int i, j, cl; int L[][] = new int[n][n]; for (i = 0; i < n; i++) L[i][i] = 1; for (cl = 2; cl <= n; cl++) { for (i = 0; i < n-cl+1; i++) { j = i+cl-1; if (seq.charAt(i) == seq.charAt(j) && cl == 2) L[i][j] = 2; else if (seq.charAt(i) == seq.charAt(j)) L[i][j] = L[i+1][j-1] + 2; else L[i][j] = max(L[i][j-1], L[i+1][j]); } } return L[0][n-1]; } public static void main(String args[]) { Scanner sc = new Scanner(System.in); String seq = sc.next(); int n = seq.length(); System.out.println(""+ lps(seq)); } }

**PYTHON PROGRAM**

s = input() n = len(s) rev = s[::-1] dp = [[0 for _ in range(n+1)] for _ in range(n+1)] for i in range(1, n+1): for j in range(1, n+1): if s[i-1] == rev[j-1]: dp[i][j] = 1 + dp[i-1][j-1] else: dp[i][j] = max(dp[i-1][j], dp[i][j-1]) print(dp[n][n])

**Question) **Given a number n, the task is to find the remainder when n is divided by 11. The input number may be very large.

Since the given number can be very large, you can not use n % 11.

**Input Specification:**

inputs a large number in the form of a string

**Output Specification:**

Return the remainder modulo 11 of input1

**Example1:**

**Input:** str = 13589234356546756

**Output:** 6

**Example2:**

**Input:** str = 3435346456547566345436457867978

**Output:** 4

**Example3:**

**input:** str = 121

**Output:** 0

**JAVA PROGRAM**

import java.util.*; import java.io.*; public class Main { static int remainder(String str) { int len = str.length(); int num, rem = 0; for (int i = 0; i < len; i++) { num = rem * 10 + (str.charAt(i) - '0'); rem = num % 11; } return rem; } public static void main(String args[]) { Scanner sc = new Scanner(System.in); String str = sc.next(); System.out.println(remainder(str)); } }

**PYTHON PROGRAM**

s, rem = input(), 0 for i in s: rem = (rem * 10 + int(i)) % 11 print(rem)

**Infosys SP and DSE Coding Questions and Solutions in Python/Java/C++**

**Question) **Williamson is an analyst he needs to analyse a particular topic for performing analysis for that he needs to find a permutation of a given object.He don’t know how to find permutation so for simplifying his work he is hiring one software developer who can code for him and find a permutation and combination of a given object.

Consider you are giving an interview to williamson for working with him. Find a permutation of given input to proof that you are fit for his requirement.

**Input Specification:**

nCr where n and r are numbers given by Williamson to you

nCr is defined as n! / (r! x (n-r)!)

Here, n! denotes the factorial of a number. Also, you have to calculate this number as modulo

**Input Specification:**

- input1: The number n.
- Input2: The number r.
- Input3: The number m,

.

**Output specification:**

- The value of nCr%m.

**Example 1:**

**Input1:** 3

**Input2:** 2

**Input3:** 10000000009

**Output:**3

**Explanation:**

n=3.r=2,m=100 So, n!=3!=6, r!=2!=2, (n-1)!= 1!=1.

So, nCr = (6/(2*1))%1000000009= 3.

**Example 2:**

**input1:** 5

**input2:** 2

**input3:** 1000000009

**Output:** 10

**Explanation:**

n=5,r=2, m=100 So, n!=5!=120, r!=2=2, (n-1)!= 3!=6.

So, nCr = (120/(2*6))%1000000009= 10.

**JAVA PROGRAM**

import java.util.*; public class Main { static int fact (int number) { int f = 1; int j = 1; while (j <= number) { f = f * j; j++; } return f; } public static void main (String args[]) { Scanner sc = new Scanner (System.in); int n = sc.nextInt (); int r = sc.nextInt (); long m = sc.nextLong (); int result = fact (n) / (fact (r) * fact (n - r)); long finalresult = (long) result % m; System.out.println ("" + result); } }

**PYTHON PROGRAM**

import math n=int(input()) r=int(input()) m=int(input()) #nCr= (n!)/((n-r)!)*(r!) numerator=(math.factorial(n)) denominator=(math.factorial(n-r))*math.factorial(r) ncr=numerator//denominator print(ncr%m)

**Infosys SP and DSE Coding Previous Year Questions & Answers**

**Q1:** A chef has n orders lined up. The waiting time penalty before an order starts getting processed is k. And for each order, a corresponding processing time t is given (in minutes) along with its order id. The earning per order is c times the time taken to process the order. Find out the profits earned for each order from 1 to n and print them in order of the input. The order is free if the profits are negative for that order i.e. the profits are max(0, profit).

The following rules are used for processing the orders:

- Pick the order which arrives first. The chef can process only one order at a time.
- Among the orders already arrived, pick the one with the least processing time.

**Input Format:**

First the number of test cases T is given. Then T test cases follow.

Each test case consists of n (the number of orders),c (the cost per minute it takes to process any order, which is the same for all orders), and k (the waiting time penalty per minute, the chef faces once an order has arrived and is there in the “waiting to be processed queue”).

Then in the following n lines, an order with its arrival time and the processing time is given.

The order id of the first of these n lines is 1, the order id of the 2nd order is 2, and so on till the nth line has the order id n.

**NOTE: **The input may or may not be sorted by the arrival time i.e. order 3 may arrive earlier than order 2 and so on.

**Output Format:** For each test case, print in a single line the profits earned for orders 1 to n, respectively.

**Constraints:**

1<=T<=10 ; 1<=n<=10^5 ; 1<=order arrival time, order processing time <= 10^9 ; 1<=k<=100 ; 1<=c<=10^4 ; Time limit: 1 second per test case

**Example :**

Input:

```
1
3 10 16
1 2
2 3
3 1
```

**Explanation: **

The number of test cases T = 1. A number of orders n = 3. Processing cost per order per minute i.e. c = 10. Penalty cost for an order already arrived but in the waiting queue per minute of waiting i.e. k = 1. Then the list of orders follows. Order 1 arrives at time t=1. the chef does nothing from t=0 to t=1.

Since he has to pick up the order which arrived first his profit earned for order 1 would be processing time*c — k*waiting time. Since the order was processed immediately as it came, the waiting time would be 0 for order 1. Hence, profit of order 1 = 2*10 — 16*0= 20. Now the time t=1+2=3. Therefore both orders 2 and 3 have arrived and are in the waiting queue.

But the chef chooses order 3 to be processed first since it has less processing time. Therefore profit for order 3 is 1*10-16*0=10, as order 3 was processed the moment it came. Now the time t=3+1=4 and the last order 2 is taken up which has been waiting for 4-2=2 minutes. Therefore the profit earned for order 2 = 3*10 — 16*2= 30 — 32 = -2. Therefore the order is free or profit = 0.

Output: 20 0 10

**Q2:**

**Solution:**

**#include**<bits/stdc++.h>

**using** **namespace** std;

**typedef** **long** **long** **int** ll;

**typedef** vector**<ll>** vi;

**#define** fo(i,s,e_ex) **for**(i=s;i<e_ex;i++)

**#define** pbb push_back

**#define** all(x) x.**begin**(),x.**end**()

**struct** task{

ll idx,at,bt;

};

**bool** comp(task p,task q){

**if**(p.at==q.at){

**return** p.bt<q.bt;

}

**return** p.at<q.at;

}

**bool** **Compare**(task a, task b){

**if**(a.bt==b.bt){

**return** a.idx>b.idx;

}

**return** a.bt>b.bt;

}

**void** solve(ll caseno){

ll i,j,n,k,d,t=0;

cin>>n>>k>>d;

vector**<task>** arr;

vector**<ll>** ans(n);

fo(i,0,n){

ll a,b;

cin>>a>>b;

task t;

t.idx=i;t.at=a;t.bt=b;

arr.pbb(t);

}

sort(all(arr),comp);

priority_queue<task, std::vector**<task>**, **decltype**(&**Compare**)> pq(**Compare**);

i=0;

**while**((!pq.empty()) || i<n){

**if**(pq.empty()){

pq.push(arr[i]);

t=arr[i].at;

i++;

}

task curr = pq.top();pq.pop();

ll wait = t-curr.at;

t+=curr.bt;

ll cost = curr.bt*k – wait*d;

cost = max(cost,0ll);

ans[curr.idx] = cost;

**while**(i<n && arr[i].at<=t){

pq.push(arr[i]);

i++;

}

}

**for**(**auto** v:ans) cout<<v<<**‘ ‘**;

cout<<endl;

}

**int** main(){

ios_base::sync_with_stdio(**false**);

cin.tie(0);cout.tie(0);

ll t=1;

cin>>t;

**for**(ll i=1;i<=t;i++){

solve(i);

}

**return** 0;

}

JOB ALERT ON INSTAGRAM |
FOLLOW NOW>> |

JOB ALERT ON YOUR EMAIL DAILY |
SUBSCRIBE NOW>> |

Keep an eye on **Dailyrecruitment.in** for the most up-to-date information about upcoming exams and results. Find out about official notices, Exam Patterns, Syllabus, Previous Question Papers, Expected Cut Off, Results, Merit List, Study Materials, and much more. Now is the time to bookmark in order to take advantage of even more amazing career opportunities.

**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 |