Ads Area

TCS Digital Previous Year Coding Questions Solved 2022 | TCS NQT Advanced Coding Questions 2023

TCS Digital Previous Year Coding Questions Solved 2022 | TCS NQT Advanced Coding Questions 2023








QUESTION 1                        

1. PT Teacher instructs students from class 1 to 10(a[]) to stand in ascending order. And then he calls randomly a number(R).

  • If the R presents in the line, give the position of the student in the line

  • If the R is not present in the line, give the position where the student should join the line

Explanation Video:
EXAMPLE / SAMPLE TEST CASE:

Example1:

Input: 

  • 6 (value of N )

  • 3 (value of R )

  • {1,2,3,4,7,9} (elements a[0] to

 a[n-1])


Output: 2

Explanation: 3 is found at index 2



Example2:

Input:

  • 5

  • 6

  • {1,2,3,4,9}


Output: 4

Explanation: 6 can be inserted at index 4

Algorithm:
  • Find if R is present in the list or not

  • If R is present print its index

  • If Not print the index of an element greater than R or insert it in the list, sort it and print its index

CODE:

In C++:
In Python:
In Java:

Post a Comment

0 Comments

Ads Area