Question: TCS NQT | 2nd October | Online Assessments
0
Entering edit mode

Question 1

Click here to Practice

In a premier championship series of sports car racing, initially, the 1st car is ahead of the 2nd car by X metres. After that, in every second, the 1st car moves ahead by n1 metres and the 2nd can moves ahead by n2 metres (in the same direction). The task is to print the number of seconds after which the 2nd car crosses the 1st car. If it is impossible to do so, then print -1

Example 1:

Input:

3 -- Value of n1
4 -- Value of n2
1 -- Value of x

Output:

2

Explanation:

Initially, the 1st car is ahead by 1 metre.

After the 1st second, the 1st and 2nd cars are at the same place.

After the 2nd second, the 2 car moves ahead of the 1st car by 1 metre.

Example 2

Input

5 ---- Value of n1
4 ---- Value of n2
1 ---- Value of x

Output:

-1

Example 3

Input

2 ---- Value of n1
12 ---- Value of n2
15 ---- Value of x

Output:

2

Constraints

1 <= n1

1 <= n2

0 <= k < 1000

Question 2

Click here to Practice

Given a sentence Str. The task is to find whether the given sentence contains all letters of the English alphabet (a to z or A to Z). If it does not, then print all missing letters of the alphabet, otherwise print 0.

Note:

  • All characters in the given sentence should be treated as case insensitive, which means that 'A' and 'a' are to be treated as the same.
  • The output should be in alphabetic order.
  • The output should contain only lowercase alphabets.
  • If none of the letters are missing print 0 as output

Example 1:

Input

The four boxing wizard starts over the quickly --- Value of Str

Output

jmp --- Missing letters

Explanation:

"The four boxing wizard starts over the quickly does not contains all the letters from a to z or A to Z as 'j', 'm' and 'p' are missing.

Example 2: Input

The four boxing wizard jumps over the quickly --- Value of Str

Output

0 -- None of the letters are missing

Explanation:

"The four boxing wizard jumps over the quickly" contains all the letters of the English alphabet. Hence, the output is 0.

Constraints:

The input sentence should not contain any special characters or numbers.

Size of Str <= 500

0
Entering edit mode

Question 2

Overview/BreakDown

  • Question is simple we are given a string the string may contain lower alphabets or uppercase letters.
    • All letters are considered case insensitive means capital A and small a are considered as one character only
  • we need to find that either all alphates from a to z are present in a string or not
    • if all alphabets are present print 0 else print all the alphabets

Approach/Explanation'

  • create a freq array size 26 and initialise all the elements in that array as 0 from i [0-26]
  • After that, we have to convert the whole string in lowercase so we can iterate over the array and check if it belongs to the uppercase alphabet or not.If the character is an Uppercase letter convert it to lowercase and mark it in freq array as true
  • keep in mind in the string we are also given a sequence of words that may have space if that is the case occur while integrating simply ignore that.
  • In the end, check if all the occurrence in our freq array is marked as true or not and print ans accordingly. if the string is missing alphabets print them else print 0.
  • Time Complexity: O(N)
ADD COMMENTlink 2.2 years ago Akshay Sharma 990
0
Entering edit mode

Question 1

Overview

  • We are given two cars and it told us that initially, car 1st is ahead of car 2.
    • It's also given that the car1 moves n1 meter every second and car 2 moves n2 meter per second
    • We need to find out if car1 can ever cross car 2 or not.
    • If car 2 is able to take over car 1 in such cases we have to print the total time taken by car 2 in seconds to overtake car 1. If car 2 is always behind car 1 then we can print -1.

PreRequists

Concept of Relative speed and basic maths

Approach/Detailed Solution

  • The first approach that comes to my mind is to calculate the position of each car every second and keep increasing car1 by n1 meters and car2 by n2 meters.
  • But we also need to consider some base cases here that is if n1>n2 then we can't overtake car1 in any case
    -As value of X is too less So naive solution will pass easily

while(car1>=car2){ time++; car1+=n1; car2+=n2; }

  • Time Complexity: O(N)
ADD COMMENTlink 2.2 years ago Akshay Sharma 990
0
Entering edit mode

where is the solution code for this ?

I want to recheck my answer

ADD COMMENTlink 23 months ago Bhargav • 0
Entering edit mode
0

Hi @Bhargav-8569 
TJO is an open community where people can discuss & learn what they like. You can check out "all submissions" tab in problem page though and learn from others accepted solutions.

ADD REPLYlink 23 months ago
admin
1.6k
0
Entering edit mode

Not

ADD COMMENTlink 20 months ago Sonu 0

Login before adding your answer.

Similar Posts
Loading Similar Posts