Skip to main content

Command Palette

Search for a command to run...

Height Checker

Published
1 min read
Height Checker
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.

A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the i<sup>th</sup> student in line.

You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the i<sup>th</sup> student in line (0-indexed).

Return the number of indices where heights[i] != expected[i].

LeetCode Problem - 1051

class Solution {
    public int heightChecker(int[] heights) {
        // Create a copy of the original array to preserve the original order
        int[] copiedArr = Arrays.copyOf(heights, heights.length);

        // Sort the copied array to compare with the original array
        Arrays.sort(copiedArr);

        int answer = 0;

        // Iterate through each element of the arrays
        for (int i=0; i<heights.length; i++){
            // Increment the count if the element in the original array
            // does not match the corresponding element in the sorted array
            if (heights[i] != copiedArr[i]) answer++;
        }

        // Return the total count of mismatches
        return answer;
    }
}

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.