Skip to main content

Command Palette

Search for a command to run...

Sort the People

Published
1 min read
Sort the People
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.

For each index i, names[i] and heights[i] denote the name and height of the i<sup>th</sup> person.

Return names sorted in descending order by the people's heights.

LeetCode Problem - 2418

class Solution {
    public String[] sortPeople(String[] names, int[] heights) {
        // Create a map to associate each height with the corresponding name
        Map<Integer, String> mp = new HashMap<>();
        for (int i = 0; i < heights.length; i++) {
            mp.put(heights[i], names[i]);
        }

        // Sort the heights array in ascending order
        Arrays.sort(heights);

        // Create a result array to store the sorted names
        String[] resultArr = new String[heights.length];

        // Fill the result array with names sorted by height in descending order
        for (int z = 0, i = heights.length - 1; i >= 0; i--) {
            resultArr[i] = mp.get(heights[z]);
            z++;
        }

        // Return the sorted array of names
        return resultArr;
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.