Question: Deloitte NLA Placement Questions | 8th Feb Slot | Arrays and Strings | Recent Online Assessment 2026 | First Occurrence Index | Matrix Modification
0
Entering edit mode

Question 1: First Occurrence of a Character (Code Nugget 2)

Problem Statement:

Write a program to find the index of the first occurrence of a specific character ch in the given string Str.

Read the input from STDIN and print the output to STDOUT. Do not write arbitrary strings anywhere in the program, as these contribute to the standard output, and test cases will fail.

Constraints:

  1. The input must be a string and have lowercase alphabets only.
  2. 1 \le \text{length of } Str \le 100
  3. The index starts from zero.

Input Format:

  • The first line contains the string Str.
  • The second line of input contains the character ch to find the position.

Output Format:

  • The output contains the position of the first occurrence of a specific character ch in the given string Str.

Sample Input 1:

Eluid

u

 

Sample Output 1:

2

 

Explanation 1:

Given, Str = "Eluid". The first occurrence of a specific character ch 'u' is 2, which is printed as the output.

 


Question 2: Matrix Element Modification (Code Nugget 1)

Problem Statement:

(Derived from the provided Input/Output specification)

You are given an m \times n matrix. Your task is to target a specific element at a given row index i and column index j, and increase its value by adding a given integer P. Output the newly updated value of that specific matrix element.

Input Format:

  • The first line contains two integers, m, and n, separated by a space, where m is the number of rows and n is the number of columns in the matrix M.
  • The next m lines each contain n integers separated by spaces, representing the elements of the matrix.
  • The following line contains two integers, i and j, separated by a space, indicating the row and column indices of the matrix element to be modified.
  • The last line contains a single integer P, the value to be added to the element at A[i][j].

Output Format:

  • A single line output should display the updated value of the matrix element at position [i][j] after increasing it by P.

Sample Input 1:

3 2
3 4
16 8
21 89
1 1
500

 

Sample Output 1:

508

 

Explanation 1:

The given matrix is:

i \ j

0

1

0

3

4

1

16

8

2

21

89

The element at the position M[1][1] = 8, so adding 500 (i.e., 8 + 500) to it, it will become 508.

 

ADD COMMENTlink 8 hours ago Sarthak • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts