[UPDATE]:

This is not a working solution as pointed out by @andhddn below.

I have a greedy algorithm that is accepted. Can't prove the correctness though. Main idea is to use the shortest string first. We sort all the string based on the number of 1s it has once, and then based on the 0s second time. Each time we try to consume as much string as possible. Result is the bigger of the 2 iterations.

Any counter example/ proof of correctness is appreciated

```
public class Solution {
public int findMaxForm(String[] strs, int m, int n) {
int result = 0;
if(strs.length == 0) return 0;
PriorityQueue<Element> oneQueue = new PriorityQueue<Element>(new oneComparator());
PriorityQueue<Element> zeroQueue = new PriorityQueue<Element>(new zeroComparator());
for(String s : strs){
int ones = 0;
int zeros = 0;
for(char c : s.toCharArray()){
if(c == '0') {
zeros++;
}else{
ones++;
}
}
Element e = new Element(ones, zeros);
oneQueue.offer(e);
zeroQueue.offer(e);
}
int numZero = m;
int numOne = n;
/*sort the string based on # of 0 each string has and try to consume as many string as possible*/
while(!zeroQueue.isEmpty()){
if(numZero >= zeroQueue.peek().zero && numOne >= zeroQueue.peek().one){
result++;
numZero -= zeroQueue.peek().zero;
numOne -= zeroQueue.peek().one;
}
zeroQueue.poll();
}
int secondResult = 0;
numZero = m;
numOne = n;
/*sort the string based on # of 1 each string has and try to consume as many string as possible*/
while(!oneQueue.isEmpty()){
if(numOne >= oneQueue.peek().one && numZero >= oneQueue.peek().zero){
secondResult++;
numZero -= oneQueue.peek().zero;
numOne -= oneQueue.peek().one;
}
oneQueue.poll();
}
return Math.max(result, secondResult);
}
class oneComparator implements Comparator<Element>{
public int compare(Element e1, Element e2){
if(e1.one == e2.one) return e1.zero - e2.zero;
return e1.one - e2.one;
}
}
class zeroComparator implements Comparator<Element>{
public int compare(Element e1, Element e2){
if(e1.zero == e2.zero) return e1.one - e2.one;
return e1.zero - e2.zero;
}
}
class Element{
public int one;
public int zero;
public Element(int one, int zero){
this.one = one;
this.zero = zero;
}
}
}```
```