There are N rectangular buildings standing along the road next to each other. The K-th building is of size H[K] × 1.
Because a renovation of all of the buildings is planned, we want to cover them with rectangular banners until the renovations are finished. Of course, to cover a building, the banner has to be at least as high as the building. We can cover more than one building with a banner if it is wider than 1.
For example, to cover buildings of heights 3, 1, 4 we could use a banner of size 4×3 (i.e. of height 4 and width 3), marked here in blue:
We can order at most two banners and we want to cover all of the buildings. Also, we want to minimize the amount of material needed to produce the banners.
What is the minimum total area of at most two banners which cover all of the buildings?
Write a function:
class Solution { public int solution(int[] H); }
that, given an array H consisting of N integers, returns the minimum total area of at most two banners that we will have to order.
Examples:
1. Given H = [3, 1, 4], the function should return 10. The result can be achieved by covering the first two buildings with a banner of size 3×2 and the third building with a banner of size 4×1:
2. Given H = [5, 3, 2, 4], the function should return 17. The result can be achieved by covering the first building with a banner of size 5×1 and the other buildings with a banner of size 4×3:
3. Given H = [5, 3, 5, 2, 1], your function should return 19. The result can be achieved by covering the first three buildings with a banner of size 5×3 and the other two with a banner of size 2×2:
4. Given H = [7, 7, 3, 7, 7], your function should return 35. The result can be achieved by using one banner of size 7×5:
5. Given H = [1, 1, 7, 6, 6, 6], your function should return 30. The result can be achieved by using banners of size 1×2 and 7×4:
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array H is an integer within the range [1..10,000].
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int wastedSpace = Arrays.stream(H).forEach
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int wastedSpace = 0;
for (int b : H) {
wastedSpace
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int wastedSpace = 0;
for (int b : H) {
wastedSpace += tallestBuilding - b;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int wastedSpace = 0;
for (int b : H) {
wastedSpace += tallestBuilding - b;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int empty = 0;
for (int b : H) {
wastedSpace += tallestBuilding - b;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).)
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average();
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
for (int i = 0; i < H.length)
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
for (int i = 0; i < H.length; i++) {
if (H[i])
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
for (int i = 0; i < H.length; i++) {
if (H[i] < avgHeight) {
break;
}
coverageLeft += H[i];
}
i
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
for (int i = 0; i < H.length; i++) {
if (H[i] < avgHeight) {
break;
}
coverageLeft += H[i];
}
// go from right
int coverageRight = 0;
for (int i = H.length)
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
for (int i = 0; i < H.length; i++) {
if (H[i] < avgHeight) {
break;
}
coverageLeft += H[i];
}
// go from right
int coverageRight = 0;
for (int i = H.length; i >= 0; i--) {
if ()
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
for (int i = 0; i < H.length; i++) {
if (H[i] < avgHeight) {
break;
}
coverageLeft += H[i];
}
// go from right
int coverageRight = 0;
for (int i = H.length; i >= 0; i--) {
if (H[i] < avgHeight) {
break;
}
coverageRight += H[i];
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[i] < avgHeight) {
break;
}
coverageLeft += H[i];
}
// go from right
int coverageRight = 0;
for (int i = H.length; i >= 0; i--) {
if (H[i] < avgHeight) {
break;
}
coverageRight += H[i];
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[i] < avgHeight) {
break;
}
coverageLeft += H[i];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; i--) {
if (H[i] < avgHeight) {
break;
}
coverageRight += H[i];
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream().sum();
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int )
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage +=
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
int remainingCoverage = 0;
int adjustment = coverageLeft > coverageRight ? 1
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
int remainingCoverage = 0;
int adjustment = coverageLeft > coverageRight ? 1 : -1;
int startPos = coverageLeft > coverageRight ? leftBound : rightBound;
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
int remainingCoverage = 0;
int adjustment = coverageLeft > coverageRight ? 1 : -1;
int startPos = coverageLeft > coverageRight ? leftBound : rightBound;
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
for (int i = rightBound; i >= 0; i--) {
remainingCoverage += H[i];
}
return coverageRight + remainingCoverage;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
for (int i = rightBound; i >= 0; i--) {
remainingCoverage += H[i];
}
return coverageRight + remainingCoverage;
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3 at Solution.solution(Solution.java:36) at Exec.run(exec.java:48) at Exec.main(exec.java:34)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4 at Solution.solution(Solution.java:36) at Exec.run(exec.java:48) at Exec.main(exec.java:34)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5 at Solution.solution(Solution.java:36) at Exec.run(exec.java:48) at Exec.main(exec.java:34)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5 at Solution.solution(Solution.java:36) at Exec.run(exec.java:48) at Exec.main(exec.java:34)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6 at Solution.solution(Solution.java:36) at Exec.run(exec.java:48) at Exec.main(exec.java:34)
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length ; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
for (int i = rightBound; i >= 0; i--) {
remainingCoverage += H[i];
}
return coverageRight + remainingCoverage;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length - 1; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
for (int i = rightBound; i >= 0; i--) {
remainingCoverage += H[i];
}
return coverageRight + remainingCoverage;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length - 1; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
syst
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
for (int i = rightBound; i >= 0; i--) {
remainingCoverage += H[i];
}
return coverageRight + remainingCoverage;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// go from left
int coverageLeft = 0;
int leftBound;
for (leftBound = 0; leftBound < H.length; leftBound++) {
if (H[leftBound] < avgHeight) {
break;
}
coverageLeft += H[leftBound];
}
// go from right
int coverageRight = 0;
int rightBound;
for (rightBound = H.length - 1; rightBound >= 0; rightBound--) {
if (H[rightBound] < avgHeight) {
break;
}
coverageRight += H[rightBound];
}
if (coverageLeft == coverageRight && leftBound == rightBound) {
return Arrays.stream(H).sum();
}
System.out.println(coverageLeft + " : " + coverageRight);
if (coverageLeft > coverageRight) {
int remainingCoverage = 0;
for (int i = leftBound; i < H.length; i++) {
remainingCoverage += H[i];
}
return coverageLeft + remainingCoverage;
}
int remainingCoverage = 0;
for (int i = rightBound; i >= 0; i--) {
remainingCoverage += H[i];
}
return coverageRight + remainingCoverage;
}
}
3 : 4
5 : 4
5 : 0
0 : 25
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound = H.length;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
for (bound = H.length - 1; bound >= 0; )
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace
for (bound = H.length - 1; bound >= 0; bound--) {
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
for (int left = 0; left <= bound; left++) {
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left])
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage +=
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
leftEmpty
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
leftEmpty = Arrays.copyOfRange(H, 0, bound).stream()
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
leftEmpty = Arrays.stream(Arrays.copyOfRange(H, 0, bound)).
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight = 0;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft = 0;
int leftCoverage = 0;
int leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
if )
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
for ()
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
for (int left = 0; left <= optimalBound; left++) {
}
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound)
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound +);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max() * leftBanner.length)
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max() * leftBanner.length)
+ (Arrays.stream(rightBanner).max() * rightBanner.length);
return bannerS
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max() * leftBanner.length)
+ (Arrays.stream(rightBanner).max() * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
// int totalBuildingsArea = Arrays.stream(H).sum();
// int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max() * leftBanner.length)
+ (Arrays.stream(rightBanner).max() * rightBanner.length);
return bannerSize;
}
}
Solution.java:16: error: cannot find symbol emptySpace += tallestBuilding - b; ^ symbol: variable tallestBuilding location: class Solution Solution.java:62: error: bad operand types for binary operator '*' int bannerSize = (Arrays.stream(leftBanner).max() * leftBanner.length) ^ first type: OptionalInt second type: int Solution.java:63: error: bad operand types for binary operator '*' + (Arrays.stream(rightBanner).max() * rightBanner.length); ^ first type: OptionalInt second type: int 3 errors
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
// int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max() * leftBanner.length)
+ (Arrays.stream(rightBanner).max() * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
// int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max() * leftBanner.length)
+ (Arrays.stream(rightBanner).max() * rightBanner.length);
return bannerSize;
}
}
Solution.java:62: error: bad operand types for binary operator '*' int bannerSize = (Arrays.stream(leftBanner).max() * leftBanner.length) ^ first type: OptionalInt second type: int Solution.java:63: error: bad operand types for binary operator '*' + (Arrays.stream(rightBanner).max() * rightBanner.length); ^ first type: OptionalInt second type: int 2 errors
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
// int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = emptySpace;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((rightEmpty + leftEmpty) < emptySpace)
optimalbound = bound;
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpt + leftEmpty) < emptySpace) {
optimalbound = bound;
emptySpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < emptySpace) {
optimalbound = bound;
emptySpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < emptySpace) {
optimalbound = bound;
emptySpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < emptySpace) {
optimalbound = bound;
emptySpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(leftEmpty + " : " + rightEmpty + " | " + )
if ((leftEmpty + rightEmpty) < emptySpace) {
optimalbound = bound;
emptySpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(leftEmpty + " : " + rightEmpty + " | " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
4 : 0 | 12 2 : 0 | 4 0 : 3 | 2
6 : 0 | 20 5 : 0 | 6 2 : 2 | 5 0 : 3 | 4
9 : 0 | 25 5 : 0 | 9 2 : 1 | 5 2 : 7 | 3 0 : 9 | 3
4 : 0 | 35 4 : 0 | 4 4 : 0 | 4 0 : 4 | 4 0 : 4 | 4
15 : 0 | 42 14 : 0 | 15 13 : 0 | 14 12 : 0 | 13 0 : 3 | 12 0 : 9 | 3
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(leftEmpty + " : " + rightEmpty + " | " + minWastedSpace );
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " leftEmpty + " : " + rightEmpty + " | " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " leftEmpty + " : " + rightEmpty + " | " + optimalBound + " - "minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
Solution.java:57: error: ')' expected System.out.println(bound + " - " leftEmpty + " : " + rightEmpty + " | " + optimalBound + " - "minWastedSpace); ^ Solution.java:57: error: not a statement System.out.println(bound + " - " leftEmpty + " : " + rightEmpty + " | " + optimalBound + " - "minWastedSpace); ^ Solution.java:57: error: ';' expected System.out.println(bound + " - " leftEmpty + " : " + rightEmpty + " | " + optimalBound + " - "minWastedSpace); ^ Solution.java:57: error: ';' expected System.out.println(bound + " - " leftEmpty + " : " + rightEmpty + " | " + optimalBound + " - "minWastedSpace); ^ 4 errors
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalBound + " - "minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalBound + " - " +minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
Solution.java:57: error: cannot find symbol System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalBound + " - " +minWastedSpace); ^ symbol: variable optimalBound location: class Solution 1 error
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
Solution.java:57: error: variable optimalbound might not have been initialized System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace); ^ 1 error
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
2 - 4 : 0 | 3 - 12 1 - 2 : 0 | 2 - 4 0 - 0 : 3 | 1 - 2
3 - 6 : 0 | 4 - 20 2 - 5 : 0 | 3 - 6 1 - 2 : 2 | 2 - 5 0 - 0 : 3 | 1 - 4
4 - 9 : 0 | 5 - 25 3 - 5 : 0 | 4 - 9 2 - 2 : 1 | 3 - 5 1 - 2 : 7 | 2 - 3 0 - 0 : 9 | 2 - 3
4 - 4 : 0 | 5 - 35 3 - 4 : 0 | 4 - 4 2 - 4 : 0 | 4 - 4 1 - 0 : 4 | 4 - 4 0 - 0 : 4 | 4 - 4
5 - 15 : 0 | 6 - 42 4 - 14 : 0 | 5 - 15 3 - 13 : 0 | 4 - 14 2 - 12 : 0 | 3 - 13 1 - 0 : 3 | 2 - 12 0 - 0 : 9 | 1 - 3
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound +);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound);
int[] rightBanner = Arrays.copyOfRange(H, bound, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
Exception in thread "main" java.lang.IllegalArgumentException: 0 > -1 at java.base/java.util.Arrays.copyOfRange(Arrays.java:4101) at Solution.solution(Solution.java:65) at Exec.run(exec.java:48) at Exec.main(exec.java:34)stdout:
2 - 4 : 0 | 3 - 12 1 - 2 : 0 | 2 - 4 0 - 0 : 3 | 1 - 2
Exception in thread "main" java.lang.IllegalArgumentException: 0 > -1 at java.base/java.util.Arrays.copyOfRange(Arrays.java:4101) at Solution.solution(Solution.java:65) at Exec.run(exec.java:48) at Exec.main(exec.java:34)stdout:
3 - 6 : 0 | 4 - 20 2 - 5 : 0 | 3 - 6 1 - 2 : 2 | 2 - 5 0 - 0 : 3 | 1 - 4
Exception in thread "main" java.lang.IllegalArgumentException: 0 > -1 at java.base/java.util.Arrays.copyOfRange(Arrays.java:4101) at Solution.solution(Solution.java:65) at Exec.run(exec.java:48) at Exec.main(exec.java:34)stdout:
4 - 9 : 0 | 5 - 25 3 - 5 : 0 | 4 - 9 2 - 2 : 1 | 3 - 5 1 - 2 : 7 | 2 - 3 0 - 0 : 9 | 2 - 3
Exception in thread "main" java.lang.IllegalArgumentException: 0 > -1 at java.base/java.util.Arrays.copyOfRange(Arrays.java:4101) at Solution.solution(Solution.java:65) at Exec.run(exec.java:48) at Exec.main(exec.java:34)stdout:
4 - 4 : 0 | 5 - 35 3 - 4 : 0 | 4 - 4 2 - 4 : 0 | 4 - 4 1 - 0 : 4 | 4 - 4 0 - 0 : 4 | 4 - 4
Exception in thread "main" java.lang.IllegalArgumentException: 0 > -1 at java.base/java.util.Arrays.copyOfRange(Arrays.java:4101) at Solution.solution(Solution.java:65) at Exec.run(exec.java:48) at Exec.main(exec.java:34)stdout:
5 - 15 : 0 | 6 - 42 4 - 14 : 0 | 5 - 15 3 - 13 : 0 | 4 - 14 2 - 12 : 0 | 3 - 13 1 - 0 : 3 | 2 - 12 0 - 0 : 9 | 1 - 3
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
2 - 4 : 0 | 3 - 12 1 - 2 : 0 | 2 - 4 0 - 0 : 3 | 1 - 2
3 - 6 : 0 | 4 - 20 2 - 5 : 0 | 3 - 6 1 - 2 : 2 | 2 - 5 0 - 0 : 3 | 1 - 4
4 - 9 : 0 | 5 - 25 3 - 5 : 0 | 4 - 9 2 - 2 : 1 | 3 - 5 1 - 2 : 7 | 2 - 3 0 - 0 : 9 | 2 - 3
4 - 4 : 0 | 5 - 35 3 - 4 : 0 | 4 - 4 2 - 4 : 0 | 4 - 4 1 - 0 : 4 | 4 - 4 0 - 0 : 4 | 4 - 4
5 - 15 : 0 | 6 - 42 4 - 14 : 0 | 5 - 15 3 - 13 : 0 | 4 - 14 2 - 12 : 0 | 3 - 13 1 - 0 : 3 | 2 - 12 0 - 0 : 9 | 1 - 3
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
Sy
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
System.out.println(Arrays.toString(leftBanner) + " | " + Arrays.toString(rightBanner));
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
2 - 4 : 0 | 3 - 12 1 - 2 : 0 | 2 - 4 0 - 0 : 3 | 1 - 2 [] | [3, 1, 4]
3 - 6 : 0 | 4 - 20 2 - 5 : 0 | 3 - 6 1 - 2 : 2 | 2 - 5 0 - 0 : 3 | 1 - 4 [] | [5, 3, 2, 4]
4 - 9 : 0 | 5 - 25 3 - 5 : 0 | 4 - 9 2 - 2 : 1 | 3 - 5 1 - 2 : 7 | 2 - 3 0 - 0 : 9 | 2 - 3 [] | [5, 3, 5, 2, 1]
4 - 4 : 0 | 5 - 35 3 - 4 : 0 | 4 - 4 2 - 4 : 0 | 4 - 4 1 - 0 : 4 | 4 - 4 0 - 0 : 4 | 4 - 4 [] | [7, 7, 3, 7, 7]
5 - 15 : 0 | 6 - 42 4 - 14 : 0 | 5 - 15 3 - 13 : 0 | 4 - 14 2 - 12 : 0 | 3 - 13 1 - 0 : 3 | 2 - 12 0 - 0 : 9 | 1 - 3 [] | [1, 1, 7, 6, 6, 6]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, bound + 1);
int[] rightBanner = Arrays.copyOfRange(H, bound + 1, H.length);
System.out.println(Arrays.toString(leftBanner) + " | " + Arrays.toString(rightBanner) + );
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
System.out.println(Arrays.toString(leftBanner) + " | " + Arrays.toString(rightBanner) + " : " + optimalbound);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
2 - 4 : 0 | 3 - 12 1 - 2 : 0 | 2 - 4 0 - 0 : 3 | 1 - 2 [3, 1] | [4] : 1
3 - 6 : 0 | 4 - 20 2 - 5 : 0 | 3 - 6 1 - 2 : 2 | 2 - 5 0 - 0 : 3 | 1 - 4 [5] | [3, 2, 4] : 0
4 - 9 : 0 | 5 - 25 3 - 5 : 0 | 4 - 9 2 - 2 : 1 | 3 - 5 1 - 2 : 7 | 2 - 3 0 - 0 : 9 | 2 - 3 [5, 3, 5] | [2, 1] : 2
4 - 4 : 0 | 5 - 35 3 - 4 : 0 | 4 - 4 2 - 4 : 0 | 4 - 4 1 - 0 : 4 | 4 - 4 0 - 0 : 4 | 4 - 4 [7, 7, 3, 7, 7] | [] : 4
5 - 15 : 0 | 6 - 42 4 - 14 : 0 | 5 - 15 3 - 13 : 0 | 4 - 14 2 - 12 : 0 | 3 - 13 1 - 0 : 3 | 2 - 12 0 - 0 : 9 | 1 - 3 [1, 1] | [7, 6, 6, 6] : 1
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
// int smallestBuilding = Arrays.stream(H).min().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
// double avgHeight = Arrays.stream(H).mapToDouble(a -> a).average().orElse(0.0);
// brute force approach
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
System.out.println(bound + " - " + leftEmpty + " : " + rightEmpty + " | " + optimalbound + " - " + minWastedSpace);
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1]
[20, 1]
[50]
[1]
[1, 10, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
System.out.println(Arrays.toString(leftBanner) + " " + Arrays.toString(rightBanner));
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
[3, 1] [4]
[5] [3, 2, 4]
[5, 3, 5] [2, 1]
[7, 7, 3, 7, 7] []
[1, 1] [7, 6, 6, 6]
function result: 16
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] [2, 1]
function result: 21
[20] [1]
function result: 50
[50] []
function result: 1
[1] []
function result: 21
[1, 10] [1]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1]
[20, 1]
[50]
[1]
[1, 10, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1]
[20, 1]
[50]
[1]
[1, 10, 1]
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] H) {
int totalBuildingsArea = Arrays.stream(H).sum();
int tallestBuilding = Arrays.stream(H).max().getAsInt();
int totalArea = tallestBuilding * H.length;
int emptySpace = 0;
for (int b : H) {
emptySpace += tallestBuilding - b;
}
int bound;
int optimalbound = H.length;
int minWastedSpace = totalArea;
for (bound = H.length - 1; bound >= 0; bound--) {
int tallestLeft, leftCoverage, leftEmpty;
tallestLeft = leftCoverage = leftEmpty = 0;
for (int left = 0; left <= bound; left++) {
if (H[left] > tallestLeft)
tallestLeft = H[left];
leftCoverage += H[left];
}
for (int left = 0; left <= bound; left++) {
leftEmpty += tallestLeft - H[left];
}
int tallestRight, rightCoverage, rightEmpty;
tallestRight = rightCoverage = rightEmpty = 0;
for (int right = bound + 1; right < H.length; right++) {
if (H[right] > tallestRight)
tallestRight = H[right];
rightCoverage += H[right];
}
for (int right = bound + 1; right < H.length; right++) {
rightEmpty += tallestRight - H[right];
}
if ((leftEmpty + rightEmpty) < minWastedSpace) {
optimalbound = bound;
minWastedSpace = (leftEmpty + rightEmpty);
}
}
int[] leftBanner = Arrays.copyOfRange(H, 0, optimalbound + 1);
int[] rightBanner = Arrays.copyOfRange(H, optimalbound + 1, H.length);
int bannerSize = (Arrays.stream(leftBanner).max().orElse(0) * leftBanner.length)
+ (Arrays.stream(rightBanner).max().orElse(0) * rightBanner.length);
return bannerSize;
}
}
The following issues have been detected: timeout errors.
Every value in the array is different. N=7,500.
running time: 2.184 sec., time limit: 0.100 sec.
Random maximum tests. N=100,000.
Killed. Hard limit reached: 6.000 sec.
Various hard hand-created tests. N=100,000.
Killed. Hard limit reached: 6.000 sec.
Values in the tests are arranged into ascending or descending pyramids. N=100,000.
Killed. Hard limit reached: 6.000 sec.