Created
December 17, 2014 08:11
-
-
Save ik11235/58a02a9935788d3fa7d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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