Question: A row in a two-dimensional array of boolean values is said to be a happy row if the number of true values in that row
A row in a two-dimensional array of boolean values is said to be a happy row if the number of true values in that row is equal to that row's index number. Write the Java method largestIndexedHappyRow, which takes a two-dimensional array of boolean values called table. You may assume that table has the same number of rows and columns. The method returns the largest index m such that the row of table at index m is a happy row. If there is no happy row in table, the method returns the value -1. For example, the return value for array aa would be 2, the return value for bb would be 1, and the return value for cc would be -1.
| aa | 0 | 1 | 2 |
| 0 | false | false | false |
| 1 | false | true | false |
| 2 | true | false | true |
| bb | 0 | 1 | 2 |
| 0 | false | true | false |
| 1 | false | true | false |
| 2 | false | true | false |
| cc | 0 | 1 | 2 |
| 0 | true | false | false |
| 1 | false | true | true |
| 2 | true | false | false |
-----------------------------------------------------------------------------------------
public static int largestIndexedHappyRow(boolean [][] table) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
