LTI Coding Questions and Solutions 2024

LTI Coding Questions for 2024 graduates

LTI Coding Questions 2024 with solutions are given here on this page. This section is the most important part of the LTI Recruitment Process 2024.

These type of Coding Questions will help you in your coding test as well as during your interview process.

  1. Written Assessment – 2 coding question : 40 mins
  2. Level 1 – 1 coding question : 60 mins (Shared)
  3. Level 2- 1 coding question : 60 mins (shared)
LTI Coding Questions

L&T Infotech Coding Questions Details

The LTI hiring process consists of multiple rounds, you need to clear each round to be eligible for the next round. The rounds have  different coding questions, whose level of difficulty goes on increasing as you proceed to the next round every time.

Here below we have given some sample practice questions for LTI coding round, based on the pattern of previous  year coding questions, make sure you practice all of these in order to prepare well for the LTI Coding Questions round.

LevelsNo. of questionsTotal Time
Automata Fix2 Coding Questions 40  mins
Level 1Coding- 1 Ques60 mins (shared)
Level 2Coding- 1 Ques60 mins (shared)

Question 1

Johnny was absent in his english class when the vowel topic was taught by the teacher . His english teacher gave him two strings and told him to find the length of the longest common subsequence which contains only vowels, as a punishment for not attending english class yesterday .

Help Jhonny by writing a code to find the length of the longest common subsequence 

Input Specification:

  • input1: First string given by his teacher
  • input2: Second string given by his teacher.

Output Specification:

  • Return the length of the longest common subsequence which contains only vowels.

Example 1:

vowelpunish

english

Output : 2

Example 2:

prepinsta

prepare

Output : 2

Question 2 

Naman on his way home found ‘N’ tokens on the ground arranged in a line horizontally. Each token has some number written on it.
Naman wants to count the longest sub-sequence of the tokens with a decreasing arrangement.
A sub-sequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements keeping the relative positions of elements same as it was in the initial sequence. A decreasing sub-sequence is a sub-sequence in which every element is strictly less than the previous number.

Your task is to help Naman in finding the longest subsequence of decreasing arrangement of tokens.

Input Specification:

  • input1: integer ‘n’ denoting size of array
  • input2: integer array ‘A’ containing ‘n’ elements

Output Specification:
For each test case, print the integer denoting the length of the longest decreasing subsequence.
Print the output of each test case in a separate line.

Constraints:

  • 1 <= n <= 5000
  • 1 <= A[i] <= 10^9
  • Time Limit: 1 sec

Example1:
Input1 : 5
Input2 : {5,0,3,2,9}

Output: 3
Explanation: The longest decreasing subsequence is of length 3, i.e. [5, 3, 2]

Example2:

input1: 9
input2: {15, 27, 14, 38, 63, 55, 46, 65, 85}

Output: 3
Explanation: The longest decreasing subsequence is of length 3, i.e. [63, 55, 46]

Question 3

Maxwell filled his university exam form in which he has filled his mid sem marks but by mistake he has filled DS marks in AI field and AI marks in DS field. He wants to update his mid sem marks but for that he has to pay some penalty.

Penalty equal to the sum of absolute differences between adjacent subject marks. 

Return the minimum penalty that must be paid by him.

Input Specification:

  • input1: length of an integer array of numbers (2 <= input 1 <= 1000)
  • input2: integer array(1 <= input2[i] <= 10000)

Example 1:

Input : arr = {4, 1, 5}

Output : 5

Explanation: Sum of absolute differences is |4-5| + |1-4| + |5-4|

Example 2:

Input : arr = {5, 10, 1, 4, 8, 7}

Output : 9

Example 3:

Input : {12, 10, 15, 22, 21, 20, 1, 8, 9}

Output : 18

Question 4

Given an array arr[] of integers, find out the maximum difference between any two elements such that the larger element appears after the smaller number.

Examples :
Input : arr = {2, 3, 10, 6, 4, 8, 1}
Output : 8
Explanation : The maximum difference is between 10 and 2.

Input : arr = {7, 9, 5, 6, 3, 2}
Output : 2
Explanation : The maximum difference is between 9 and 7.

Question 5

Given an array of integers (both odd and even), the task is to arrange them in such a way that odd and even values come in alternate fashion in non-decreasing order(ascending) respectively. 

  • If the smallest value is Even then we have to print Even-Odd pattern.
  • If the smallest value is Odd then we have to print Odd-Even pattern.

Note: No. of odd elements must be equal to No. of even elements in the input array.

Examples: 

Input:  arr[] = {1, 3, 2, 5, 4, 7, 10} 

Output: 1, 2, 3, 4, 5, 10, 7 

Smallest value is 1(Odd) so output will be Odd-Even pattern.

Input: arr[] = {9, 8, 13, 2, 19, 14} 

Output: 2, 9, 8, 13, 14, 19 

Smallest value is 2(Even) so output will be Even-Odd pattern.

Question 6

Given a string of consecutive digits and a number Y, the task is to find the number of minimum sets such that every set follows the below rule:
Set should contain consecutive numbers
No digit can be used more than once.
The number in the set should not be more than Y.
Examples:

Input: s = “1234”, Y = 30
Output: 3

Three sets of {12, 3, 4}

Input: s = “1234”, Y = 4
Output: 4
Four sets of {1}, {2}, {3}, {4}

Question 7

Alice is a kindergarten teacher. She wants to give some candies to the children in her class.  All the children sit in a line and each of them has a rating score according to his or her performance in the class.  Alice wants to give at least 1 candy to each child. If two children sit next to each other, then the one with the higher rating must get more candies. Alice wants to minimize the total number of candies she must buy.

Example

She gives the students candy in the following minimal amounts: . She must buy a minimum of 10 candies.

Function Description

Complete the candies function in the editor below.

candies has the following parameter(s):

  • int n: the number of children in the class
  • int arr[n]: the ratings of each student

Returns

  • int: the minimum number of candies Alice must buy

Input Format

The first line contains an integer, , the size of .

Each of the next  lines contains an integer  indicating the rating of the student at position .

Sample Input 0

3

1

2

2

Sample Output 0

4

Explanation 0

Here 1, 2, 2 is the rating. Note that when two children have equal rating, they are allowed to have a different number of candies. Hence optimal distribution will be 1, 2, 1.

Sample Input 1

10

2

4

2

6

1

7

8

9

2

1

Sample Output 1

19

Sample Input 2

8

2

4

3

5

2

6

4

5

Sample Output 2

12

Question 8

Given a string s, the task is to find out the minimum number of adjacent swaps required to make a string is palindrome. If it is not possible, then return -1.

Examples:
Input: aabcb
Output: 3

Explanation:
After 1st swap: abacb
After 2nd swap: abcab
After 3rd swap: abcba

Input: adbcdbad
Output: -1

Question 9

Ronny is given a string along with the string which contains single character x. She has to remove the character x from the given string. Help her write a function to remove all occurrences of x character from the given string.

Input Specification:

  • input1: input string s
  • input2: String containing any character x

Output Specification:
String without the occurrence of character x

Example 1:
Input1: Prepinsta
input2: i

Output: prepnst

Explanation: As i is the character which is required to be removed, therefore all the occurrences of i are removed, keeping all other characters.

Question 10

Encryption is needed to be done in important chats between army officers so that no one else can read it .
Encryption of message is done by replacing each letter with the letter at 3
positions to the left
e.g. ‘a’ is replaced with ‘x. ‘b’ with ‘y’ … ‘d’ with ‘a’ and so on.

Given a encrypted input string find the corresponding plaintext and return the plaintext as output string.

Note:- All the characters are in the lower case for input and output strings

Input Specification
input1: the ciphertext

Output Specification
Return the corresponding plaintext.

Example1:
input 1: ABCDEFGHIJKLMNOPQRSTUVWXYZ
output: XYZABCDEFGHIJKLMNOPQRSTUVW

Example2:
Input 1: ATTACKATONCE
output: EXXEGOEXSRGI

One comment on “LTI Coding Questions and Solutions 2024”


  • iPhone13

    A company manufactures different types of software products. They deliver their products to their N clients. Whenever the company fulfills the complete order of a client. the orderID generated is the concatenation of the number of products delivered for every committed product type. The head of the sales team wishes to find the clientwise data for the total number of products of any type delivered to every client.

    63

    66

    67

    68

    69

    78

    int main() 71 (

    72

    73

    74

    75

    Write an algorithm for the head of sales team to calculate the total number of products of any type delivered to the respective clients.

    76 77

    78

    Input

    79

    80

    The first line of the input consists of an

    81

    82

    integer numOfClients, representing the number of clients (N). The second line consists of N space separated integers orderiDo

    83

    84

    array s

    input

    scanf(

    order

    for (

    array single

    array sing

    return an

    arra

    for

    1

    pr

    orderID, orderiD

    representing the orderIDs of the orders delivered to the clients.

    90

    Output

    92

    93

    Print N space-seperated integers representing the clientwise data for the total number of products of any type delivered to each of the respective clients.