Skip to main content

Command Palette

Search for a command to run...

Maximum Width Ramp

Published
2 min read
Maximum Width Ramp
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 ramp in an integer array nums is a pair (i, j) for which i < j and nums[i] <= nums[j]. The width of such a ramp is j - i.

Given an integer array nums, return the maximum width of a ramp in nums. If there is no ramp in nums, return 0.

LeetCode Problem - 962

class Solution {
    public int maxWidthRamp(int[] nums) {
        int[] max_right = new int[nums.length]; // Array to store the maximum value to the right of each index
        int n = nums.length;
        int prev_value = 0; // Variable to keep track of the maximum value while iterating

        // Build the max_right array by storing the maximum value from the right side for each index
        for (int i = n - 1; i >= 0; i--) {
            max_right[i] = Math.max(prev_value, nums[i]); // Update max_right with the max value so far
            prev_value = max_right[i]; // Update prev_value for the next iteration
        }

        int res = 0; // Variable to store the maximum width of the ramp
        int l = 0; // Left pointer to find the valid ramp

        // Iterate through the array with a right pointer
        for (int r = 0; r < n; r++) {
            // Adjust the left pointer until a valid ramp is found where nums[l] <= max_right[r]
            while (nums[l] > max_right[r]) {
                System.out.println(max_right[r]); // Debug statement to print the current value of max_right[r]
                l++; // Move left pointer to the right
            }
            // Calculate the ramp width and update the result
            res = Math.max(res, r - l);
        }

        return res; // Return the maximum ramp width found
    }
}

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.

Maximum Width Ramp