Skip to content

Instantly share code, notes, and snippets.

@ik11235
Last active August 29, 2015 14:14
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 ik11235/814b7414b27f4fd25fd6 to your computer and use it in GitHub Desktop.
Save ik11235/814b7414b27f4fd25fd6 to your computer and use it in GitHub Desktop.
class PeacefulLine {
public:
string makeLine(vector<int> x) {
sort(x.begin(),x.end());
int ans=0;
int cnt=1;
for (int i=1; i < x.size(); i++) {
if(x[i-1]==x[i])
{
cnt++;
ans=max(cnt,ans);
}
else
cnt=1;
}
if(ans<=(x.size()+1)/2)
return "possible";
else
return "impossible";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment