-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jinendra Jain
authored
Nov 7, 2020
1 parent
399d911
commit 38b505d
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Sort 0 1 2\n", | ||
"\n", | ||
"You are given an integer array/list(ARR) of size N. It contains only 0s, 1s and 2s. Write a solution to sort this array/list in a 'single scan'.<br>\n", | ||
"<br>\n", | ||
"'Single Scan' refers to iterating over the array/list just once or to put it in other words, you will be visiting each element in the array/list just once.<br>\n", | ||
"<br>\n", | ||
"Note:You need to change in the given array/list itself. Hence, no need to return or print anything. <br>\n", | ||
"<br>\n", | ||
"Input format :<br>\n", | ||
"The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.<br>\n", | ||
"<br>\n", | ||
"First line of each test case or query contains an integer 'N' representing the size of the array/list.<br>\n", | ||
"<br>\n", | ||
"Second line contains 'N' single space separated integers(all 0s, 1s and 2s) representing the elements in the array/list.<br>\n", | ||
"Output Format :<br>\n", | ||
"For each test case, print the sorted array/list elements in a row separated by a single space.<br>\n", | ||
"<br>\n", | ||
"Output for every test case will be printed in a separate line.<br>\n", | ||
"<br>\n", | ||
"Constraints :<br>\n", | ||
"1 <= t <= 10^2<br>\n", | ||
"0 <= N <= 10^5<br>\n", | ||
"Time Limit: 1 sec<br>\n", | ||
"<br>\n", | ||
"Sample Input 1:<br>\n", | ||
"1<br>\n", | ||
"7<br>\n", | ||
"0 1 2 0 2 0 1<br>\n", | ||
"Sample Output 1:<br>\n", | ||
"0 0 0 1 1 2 2 <br>\n", | ||
"Sample Input 2:<br>\n", | ||
"2<br>\n", | ||
"5<br>\n", | ||
"2 2 0 1 1<br>\n", | ||
"7<br>\n", | ||
"0 1 2 0 1 2 0<br>\n", | ||
"Sample Output 2:<br>\n", | ||
"0 1 1 2 2 <br>\n", | ||
"0 0 0 1 1 2 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"1\n", | ||
"11\n", | ||
"2 2 1 1 2 1 0 0 1 2 2 \n", | ||
"0 0 1 1 1 1 2 2 2 2 2\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"#Remove All Coding Ninjas Code, Then Paste my Code\n", | ||
"loop=int(input())\n", | ||
"list=[]\n", | ||
"for i in range(loop):\n", | ||
" no_of_ele=int(input())\n", | ||
" if no_of_ele!=0:\n", | ||
" list=[int(x) for x in input().split()]\n", | ||
" list.sort()\n", | ||
" print(*list)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |