package org.wesome.dsalgo;
public class FindOneInMatrix {
public static int findOneInMatrix(int[][] arr, int ROW, int COL) {
int rowIndx, colIndx = COL - 1, maxOnes = -1;
for (rowIndx = 2; rowIndx < ROW; rowIndx++) {
while (colIndx >= 0 && arr[rowIndx][colIndx] == 1) {
colIndx--;
maxOnes = rowIndx;
}
}
return maxOnes;
}
}
package org.wesome.dsalgo;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.wesome.dsalgo.FindOneInMatrix.findOneInMatrix;
public class FindOneInMatrixTest {
@Test
void findOneInMatrixTest() {
int[][] arr = {{0, 0, 0, 0, 1},
{0, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 1}};
Assertions.assertEquals(3, findOneInMatrix(arr, 5, 5));
}
}
plugins {
id 'java'
id "io.freefair.lombok" version "6.2.0"
}
group = 'org.wesome'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
}
test {
useJUnitPlatform()
}