Rick is really fond of fruit juices, but he is bored of their traditional flavours. Therefore, he has decided to mix as many of them as possible to obtain something entirely new as a result.
He has N glasses, numbered from 0 to N-1, each containing a different kind of juice. The J-th glass has capacity[J] units of capacity and contains juice[J] units of juice. In each glass there is at least one unit of juice.
Rick want to create a multivitamin mix in one of the glasses. He is going to do it by pouring juice from several other glasses into the chosen one. Each of the used glasses must be empty at the end (all of the juice from each glass has to be poured out).
What is the maximum number of flavours that Rick can mix?
Write a function:
class Solution { public int solution(int[] juice, int[] capacity); }
that, given arrays juice and capacity, both of size N, returns the maximum number of flavours that Rick can mix in a single glass.
Examples:
1. Given juice = [10, 2, 1, 1] and capacity = [10, 3, 2, 2], your function should return 2. Rick can pour juice from the 3rd glass into the 2nd one.
2. Given juice = [1, 2, 3, 4] and capacity = [3, 6, 4, 4], your function should return 3. Rick can pour juice from the 0th and 2nd glasses into the 1st one.
3. Given juice = [2, 3] and capacity = [3, 4], your function should return 1. No matter which glass he chooses, Rick cannot pour juice from the other one into it. The maximum number of flavours in the chosen glass is 1.
4. Given juice = [1, 1, 5] and capacity = [6, 5, 8], your function should return 3. Rick can mix all juices in the 2nd glass.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [2..100,000];
- each element of arrays juice and capacity is an integer within the range [1..1,000,000,000];
- arrays juice and capacity have the same length, equal to N;
- for each J juice[J] ≤ capacity[J].
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
for(int i =0; i < capacity.length; i++){
juicesSorted.clear();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
valueRemoved = juice[i];
juicesSorted.remove(valueRemoved);
for(Integer valueJ : juicesSorted){
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
for(int i =0; i < capacity.length; i++){
juicesSorted.clear();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
valueRemoved = juice[i];
juicesSorted.remove(valueRemoved);
for(Integer valueJ : juicesSorted){
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
int unitInGlass;
for(int i =0; i < capacity.length; i++){
juicesSorted.clear();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
valueRemoved = juice[i];
juicesSorted.remove(valueRemoved);
for(Integer valueJ : juicesSorted){
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator
for(int i =0; i < capacity.length; i++){
juicesSorted.clear();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
valueRemoved = juice[i];
juicesSorted.remove(valueRemoved);
for(Integer valueJ : juicesSorted){
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator = false;
for(int i =0; i < capacity.length; i++){
juicesSorted.clear();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
valueRemoved = juice[i];
juicesSorted.remove(valueRemoved);
for(Integer valueJ : juicesSorted){
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator = true;
for(int i =0; i < capacity.length; i++){
juicesSorted.clear();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
valueRemoved = juice[i];
juicesSorted.remove(valueRemoved);
for(Integer valueJ : juicesSorted){
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator = true;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
if()
for(Integer valueJ : juicesSorted){
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator = true;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator)
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator = true;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator = true;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator = true;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
juicesSorted.stream().forEach(System.out::print);
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
valueJ.stream().forEach(System.out::print);
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
valueJ.stream().forEach(System.out::print);
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
Solution.java:34: error: cannot find symbol valueJ.stream().forEach(System.out::print); ^ symbol: method stream() location: variable valueJ of type Integer 1 error
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
System.out.println(valueJ);
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
System.out.println(valueJ);
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
1 1 1 1 1
1 1 2 1 2 1
2 2
1 1 1 1 5
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
System.out.println();
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
System.out.println(valueRemoved);
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
10 2 1 1
1 2 3 4
2 3
1 1 5
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
System.out.println(valueRemoved);
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
System.out.println(valueJ);
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
1 1
1 2
2
1 1 5
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
System.out.println(valueJ);
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
1
1 1
1 1
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
System.out.println(valueJ);
System.out.println(valueJ);
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(valueJ);
System.out.println(capacities.get(i));
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
1 0 1 1 1 1
1 4 1 1 2 1 1 0
2 1
1 3 1 3
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(valueJ);
System.out.println(capacities.get(i));
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(valueJ);
System.out.println(capacities.get(i));
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
01111 0 1 1 1 1
24101 4 1 1 2 1 1 0
112 1
5431 3 1 3
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(valueJ);
System.out.println(capacities.get(i));
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(valueJ);
System.out.println(capacities.get(i));
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
0111 10211 1 0 1 1 1 1
2410 1234 1 4 1 1 2 1 1 0
11 23 2 1
543 115 1 3 1 3
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
System.out.println("");
juicesS.stream().forEach(System.out::print);
System.out.println("");
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(valueJ);
System.out.println(capacities.get(i));
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);
System.out.println("");
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(valueJ);
System.out.println(capacities.get(i));
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
0111 11210 1 0 1 1 1 1
2410 1234 1 4 1 1 2 1 1 0
11 23 2 1
543 115 1 3 1 3
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);
System.out.println("");
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(valueJ);
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);
System.out.println("");
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
break;
}
mixed+=valueJ;
System.out.println(capacities.get(i));
System.out.println(valueJ);
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
0111 11210 0 1 1 1 1 1
2410 1234 4 1 1 1 1 2 0 1
11 23 1 2
543 115 3 1 3 1
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);
System.out.println("");
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
conti;
}
mixed+=valueJ;
System.out.println(capacities.get(i));
System.out.println(valueJ);
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
capacities.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);
System.out.println("");
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
System.out.println(capacities.get(i));
System.out.println(valueJ);
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
0111 11210 0 1 1 1 1 1 1 1 1 2 1 1 1 2
2410 1234 2 2 2 3 4 1 4 3 4 4 1 1 1 2 0 1
11 23 1 3 1 2
543 115 5 1 5 5 4 1 4 5 3 1 3 1
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juice);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juice);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
Solution.java:22: error: no suitable method found for addAll(int[]) juicesSorted.addAll(juice); ^ method Collection.addAll(Collection<? extends Integer>) is not applicable (argument mismatch; int[] cannot be converted to Collection<? extends Integer>) method List.addAll(Collection<? extends Integer>) is not applicable (argument mismatch; int[] cannot be converted to Collection<? extends Integer>) Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juices = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juicesSorted = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
List<Integer> juicesSorted = new ArrayList<Integer>();
juicesSorted.addAll(juices);
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juicesSorted = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juicesSorted = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juicesSorted = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] juice, int[] capacity) {
// write your code in Java SE 8
List<Integer> capacities = IntStream.range(0, capacity.length)
.mapToObj(c -> capacity[c] - juice[c])
.collect(Collectors.toList());
List<Integer> juicesSorted = Arrays.stream(juice)
.boxed()
.collect(Collectors.toList());
Collections.sort(juicesSorted);
Integer valueRemoved;
int count=1;
int mixed=0;
int maxCount=0;
boolean comparator;
for(int i =0; i < capacity.length; i++){
valueRemoved = juice[i];
comparator = true;
for(Integer valueJ : juicesSorted){
if(valueJ == valueRemoved && comparator){
comparator =false;
continue;
}
mixed+=valueJ;
if(mixed<=capacities.get(i)){
count++;
}
else{
break;
}
}
mixed=0;
if(maxCount < count){
maxCount = count;
}
count=1;
}
/*
capacities.stream().forEach(System.out::print);
System.out.println("");
juices.stream().forEach(System.out::print);
System.out.println("");
juicesSorted.stream().forEach(System.out::print);*/
return maxCount;
}
}
The following issues have been detected: timeout errors.
Tests in which the glass with the biggest capacity is not the one that should be picked as the base.
Tests in which the glass with the largest empty space is not the picked as the base.
All kind of tests, N <= 100,000. Points x 2.
Killed. Hard limit reached: 8.000 sec.
Big tests with extreme values. Points x 2.
running time: 0.108 sec., time limit: 0.100 sec.
Tests in which glasses have big capacity. Points x 2.
Killed. Hard limit reached: 8.000 sec.