Delete Greatest Value in Each Row

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 m x n matrix grid consisting of positive integers.
Perform the following operation until grid becomes empty:
Delete the element with the greatest value from each row. If multiple such elements exist, delete any of them.
Add the maximum of deleted elements to the answer.
Note that the number of columns decreases by one after each operation.
Return the answer after performing the operations described above.
LeetCode Problem - 2500
class Solution {
public int deleteGreatestValue(int[][] grid) {
// Sort each row in the grid
for (int[] row : grid) {
Arrays.sort(row);
}
int col = grid[0].length; // Get the number of columns
int row = grid.length; // Get the number of rows
List<Integer> al = new ArrayList<>(); // Initialize a list to store column elements
int answer = 0; // Initialize the answer to 0
// Iterate over columns from right to left
for (int i = col - 1; i >= 0; i--) {
al.clear(); // Clear the list for the new column
// Add the elements of the current column to the list
for (int j = 0; j < row; j++) {
al.add(grid[j][i]);
}
// Sort the list to find the greatest value in the column
Collections.sort(al);
// Add the greatest value in the column to the answer
answer += al.get(al.size() - 1);
}
return answer; // Return the final answer
}
}




