We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import math
import os
import random
import re
import sys
if name == 'main':
nm = input().split()
n = int(nm[0])
m = int(nm[1])
arr = []
for _ in range(n):
arr.append(list(map(int, input().rstrip().split())))
#taking one duplicate of arr
arrdup = arr[:]
k = int(input().strip())
for i in range(0,len(arr)-1):
for j in range (i+1,len(arr)) :
#("we are now comparing : ", arr[i][k],arr[j][k])
if arr[i][k] > arr[j][k] :
arr[i], arr[j] = arr[j], arr[i]
if arr[i][k] == arr[j][k] :
if arrdup.index(arr[i]) > arrdup.index(arr[j]):
arr[i], arr[j] = arr[j], arr[i]
for i in arr :
print(*i)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Athlete Sort
You are viewing a single comment's thread. Return to all comments →
Solution with our Using Lamda function
import math import os import random import re import sys
if name == 'main': nm = input().split()