TCS NQT Coding Question-4: Airport Security Check

TCS NQT Coding Question-4: Airport Security Check

In this post, we will see the solution of the Python Coding Question which is already asked in the TCS NQT Exam.
Problem Statement: Airport security team have confiscated several items of the passengers at the security check point. All the items have been dropped into a box (array). Each item possesses a certain amount of risk items [0,1,2]. Here, the risk severity of the items represents an array [] of N number of integral values. The task here is to sort the items based on their levels of risk in the array. The risk values range from 0 to 2.

Example :

Input:
6 -> Value of N
[1,0,2,0,1,0]-> Element of arr[0] to arr[N-1], while input each element is separated by space.

Output :
0 0 0 1 1 2 -> Element after sorting based on risk severity 

Example 2:
input : 
9 -> Value of N 
[2,1,0,2,1,0,0,1,2] -> Element of arr[0] to arr[N-1], while input each element is separated by a space.

Output: 
0 0 0 1 1 1 2 2 2 ->Elements after sorting based on risk severity.

Explanation:
In the above examples, the input is an array of size N consisting of only 0’s, 1’s and 2s. The output is a sorted array from 0 to 2 based on the risk severity.

Solution:

# taking inputs
N = int(input())
risk_array = list(map(int,input().strip().split()))

# sorted the list in ascending order
risk_array.sort()


# printing the outputs
for risk in risk_array:
    print(risk, end=" ")

Output:

6
[1,0,2,0,1,0]
0 0 0 1 1 2

Leave a Reply

Your email address will not be published. Required fields are marked *

📢 Need further clarification or have any questions? Let's connect!

Connect 1:1 With Me: Schedule Call


If you have any doubts or would like to discuss anything related to this blog, feel free to reach out to me. I'm here to help! You can schedule a call by clicking on the above given link.
I'm looking forward to hearing from you and assisting you with any inquiries you may have. Your understanding and engagement are important to me!

This will close in 20 seconds