Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created July 16, 2016 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/fb463d7bfe70022f26fc6e0854f94228 to your computer and use it in GitHub Desktop.
Save jianminchen/fb463d7bfe70022f26fc6e0854f94228 to your computer and use it in GitHub Desktop.
bulbs - facebook code lab - partial correct answer
public class Solution {
public int bulbs(List<Integer> a) {
if(a == null || a.size() == 0)
return 0;
int count = 0;
while(a !=null && a.size()> 0)
{
Integer previous = a.get(0);
a.remove(0);
if(previous.intValue() ==0)
{
count ++;
List<Integer> opposite = getOpposite(a);
a = opposite;
}
}
return count;
}
public List<Integer> getOpposite(List<Integer> a)
{
List<Integer> list = new ArrayList<Integer>();
if(a== null)
return list;
for(int i=0; i< a.size(); i++)
{
int val = Integer.valueOf(a.get(i));
Integer tmp = val == 0? Integer.valueOf(1):Integer.valueOf(0);
list.add(tmp);
}
return list;
}
}
@jianminchen
Copy link
Author

Here is the error message to work on - from facebook code lab:
Time Complexity
Almost there. Your solution is not well optimized for runtime. Focus your effort in solving the problem in shorter time frame.
Partially Correct Answer. Make your solution more efficient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment