278B - New Problem - CodeForces Solution


brute force strings *1500

Please click on ads to support us..

Python Code:

ch1=""

n=int(input())
a=0
l=[]
li=[]
for i in range (97,123):
    l.append(chr(i))
for i in range (97,123):
    for j in range (97,123):
        l.append(chr(i)+chr(j))
for i in range (n):
    ch=input()
    ch1=ch1+":"+ch
for j in (l):
    if j not in ch1:
            print(j)
            a=1
            break
    if a==1:
        break

C++ Code:

#include <bits/stdc++.h>
using namespace std;

int main(void) {
  cin.tie(nullptr)->sync_with_stdio(false);

  unordered_set<string> st;
  int n; cin >> n;

  while (n--) {
    string a; cin >> a;
    for (int i = 0; i < a.size(); ++i) {
      string p = "";

      for (int j = i; j < a.size(); ++j) {
        p += a[j];
        st.insert(p);
      }
    }
  }

  queue<string> que;
  
  for (int i = 0; i < 26; ++i) {
    string a = "";
    a += 'a' + i;
    que.push(a);
  }

  while (true) {
    auto p = que.front(); que.pop();

    if (st.find(p) == st.end()) {
      cout << p << "\n";
      return 0;
    }

    for (char c = 'a'; c <= 'z'; ++c) {
      p.push_back(c);
      que.push(p);
      p.pop_back();
    }
  }
}


Comments

Submit
0 Comments
More Questions

1183B - Equalize Prices
1481A - Space Navigation
1437B - Reverse Binary Strings
1362B - Johnny and His Hobbies
1299A - Anu Has a Function
1111A - Superhero Transformation
954A - Diagonal Walking
39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs
755C - PolandBall and Forest
456B - Fedya and Maths
376B - IOU
1623B - Game on Ranges
1118A - Water Buying
1462C - Unique Number
301A - Yaroslav and Sequence
38A - Army
38C - Blinds
1197A - DIY Wooden Ladder
1717D - Madoka and The Corruption Scheme
1296D - Fight with Monsters
729D - Sea Battle
788A - Functions again