
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find String Where Trygub is Not a Substring in C++
Suppose we have a string S with n lowercase English letters. We have to reorder the characters in S, so that "trygub" is not a subsequence of the resulting string.
So, if the input is like S = "pintontrygubabc", then the output will be "abbcginnoprttuy".
Steps
To solve this, we will follow these steps −
sort the array S return S
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; string solve(string S){ sort(S.begin(), S.end()); return S; } int main(){ string S = "pintontrygubabc"; cout << solve(S) << endl; }
Input
"pintontrygubabc"
Output
abbcginnoprttuy
Advertisements