Skip to content

Commit 86ebe80

Browse files
committed
Update largest container brute force file name
1 parent 82195e3 commit 86ebe80

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

kotlin/src/main/kotlin/common/twopointers/largestcontainer/LargestContainerNaive.kt renamed to kotlin/src/main/kotlin/common/twopointers/largestcontainer/LargestContainerBruteForce.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@ package common.twopointers.largestcontainer
33
import kotlin.math.max
44
import kotlin.math.min
55

6-
class LargestContainerNaive {
6+
class LargestContainerBruteForce {
77

88
fun solution(heights: List<Int>): Int {
9+
val n = heights.size
910
var maxWater = 0
1011
// Find the maximum amount of water stored between all pairs of lines.
11-
for (i in heights.indices) {
12+
for (i in 0 until n) {
1213
for (j in i + 1 until heights.size) {
13-
// Select minimum among them. Water can be contained depending on lower height.
14-
val width = min(heights[i], heights[j])
15-
val length = j - i
16-
// Rectangle formula.
17-
val water = width * length
14+
val water = min(heights[i], heights[j]) * (j - i)
1815
maxWater = max(maxWater, water)
1916
}
2017
}

kotlin/src/test/kotlin/common/twopointers/largestcontainer/LargestContainerNaiveTest.kt renamed to kotlin/src/test/kotlin/common/twopointers/largestcontainer/LargestContainerBruteForceTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package common.twopointers.largestcontainer
33
import org.junit.jupiter.api.Test
44
import kotlin.test.assertEquals
55

6-
class LargestContainerNaiveTest {
6+
class LargestContainerBruteForceTest {
77

8-
private val question = LargestContainerNaive()
8+
private val question = LargestContainerBruteForce()
99

1010
@Test
1111
fun `Verify solution`() {

0 commit comments

Comments
 (0)