We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I got similar but faster algorithm for this.
I first count the apperance of each char in the given string 's'.
Then, I sort these char in decending order.
Finally, create a double loop as the matrix representation and only loop through the upper triangle elements to construct the new string 't'.
Therefore, the first effective nonzero length of the 't' is the answer.
Two Characters
You are viewing a single comment's thread. Return to all comments →
Hi Racsoth,
I got similar but faster algorithm for this. I first count the apperance of each char in the given string 's'. Then, I sort these char in decending order. Finally, create a double loop as the matrix representation and only loop through the upper triangle elements to construct the new string 't'.
Therefore, the first effective nonzero length of the 't' is the answer.
Here is my code:
using namespace std;
bool myCompare( pair lhs, pair rhs){ return lhs.first > rhs.first; }
vector > getOrderedChar(const string & s){ map count; for(unsigned i=0 ; i
}
int getCount(string & str, char a, char b){ // Construct t from a, b only. string tmp; for( unsigned i ; i
int main(){ int len; cin >> len; string s; cin >> s; auto orderCharVec = getOrderedChar(s);
}