1076A - Minimizing the String - CodeForces Solution


greedy strings *1200

Please click on ads to support us..

Python Code:

n = int(input())
s = input()
i = 0
while i!= n-1 and s[i] <= s[i+1]:
	i += 1
if i == n-1:
	print(s[:i])
else:
	print(s[:i]+s[i+1:])

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
const long long MOD = 1e9 + 7, OO = 1e18;
const double PI = acos(-1);
const int N = 1e5 + 5;

ll t = 1;

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i =0; i< n-1;i++){
        if (s[i] > s[i+1]){
            for (int j = 0; j < i;j++){
                cout << s[j];
            }
            for (int j = i+1; j < n;j++){
                cout << s[j];
            }
            return ;
        }
    }
    for (int i =0; i< n-1 ;i++) cout << s[i];
    return;
}

int main() {
    IO
    
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

    


Comments

Submit
0 Comments
More Questions

600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know
1672A - Log Chopping
300A - Array
48D - Permutations
677C - Vanya and Label
1583B - Omkar and Heavenly Tree
1703C - Cypher
1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets