Athlete Sort Hacker Rank Solution – Queslers

Problem : Athlete Sort Hacker Rank Solution

You are given a spreadsheet that contains a list of N athletes and their details (such as age, height, weight and so on). You are required to sort the data based on the Kth attribute and print the final resulting table. Follow the example given below for better understanding.

Athlete Sort in python - Hacker Rank Solution

Note that K is indexed from 0 to M-1, where M is the number of attributes.
Note: If two attributes are the same for different rows, for example, if two atheletes are of the same age, print the row that appeared first in the input.


Input Format :

The first line contains N and M separated by a space.
The next N lines each contain M elements.
The last line K contains.

Constraints :

  • 1 <= N, M <= 1000
  • 0 <= K < M
  • Each element <= 1000

Output Format :

Print the N lines of the sorted table. Each line should contain the space separated elements. Check the sample below for clarity.


Sample Input :

5 3
10 2 5
7 1 0
9 9 9
1 23 12
6 5 9
1

Sample Output :

7 1 0
10 2 5
6 5 9
9 9 9
1 23 12

Explanation :

The details are sorted based on the second attribute, since K is zero-indexed.

Athlete Sort Hacker Rank Solution in python 2

N,M = map(int,raw_input().split())
lines = []
for i in xrange(N):
    lines.append(map(int,raw_input().split()))
K = int(raw_input())
lines = sorted(lines,key = lambda x: x[K])
for line in lines:
    print ' '.join(str(k) for k in line)

Athlete Sort Hacker Rank Solution in python 3

#!/bin/python3

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())))

    k = int(input())

    P=sorted(arr,key=lambda row:row[k])
    for i in range(len(P)):
        for j in range(len(P[i])):
            print(P[i][j], end=' ')
        print()

Athlete Sort Hacker Rank Solution in pypy

# Enter your code here. Read input from STDIN. Print output to STDOUT
N, M = map(int, raw_input().split())
rows = [raw_input() for _ in range(N)]
K = input()

for row in sorted(rows, key=lambda row: int(row.split()[K])):
    print(row)

Athlete Sort Hacker Rank Solution in pypy 3

# Enter your code here. Read input from STDIN. Print output to STDOUT
tbl = []
rc = input()
(r,c) = map(int, rc.split())

for i in range(r):
    _row = input()
    row = list(map(int, _row.split()))
    tbl.append(row)

idx = int(input())
    
tbls = sorted(tbl, key = lambda x: x[idx])
for t in tbls:
    print (*t)
    
Athlete Sort Hacker Rank Solution Review:

In our experience, we suggest you solve this Athlete Sort Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

hackerrank.com/challenges/python-sort-sort/forum is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution

Athlete Sort Hacker Rank Solution Conclusion:

I hope this Athlete Sort Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

Mini-Max Sum Hacker Rank Solution

String Validators Hacker Rank Solution

Text Alignment Hacker Rank solution

String validators Hacker Rank Solution

Staircase Hacker Rank Solution

Leave a Reply

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