Skip to content

Instantly share code, notes, and snippets.

@ik11235
Created December 17, 2014 08:11
Show Gist options
  • Save ik11235/58a02a9935788d3fa7d3 to your computer and use it in GitHub Desktop.
Save ik11235/58a02a9935788d3fa7d3 to your computer and use it in GitHub Desktop.
class LightSwitchingPuzzle {
public:
int minFlips(string state) {
int ans=0;
for(int i=0;i<state.size();i++)
{
if(state[i]=='Y')
{
ans++;
for(int j=i;j<state.size();j+=(i+1))
{
if(state[j]=='N')
state[j]='Y';
else
state[j]='N';
}
}
}
return ans;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment