dvjsharma

Untitled

Aug 21st, 2025
222
0
Never
8
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool isTwoDiff(const string &a, const string &b) {
  5.     if (a.size() != b.size()) return false;
  6.     int diff = 0;
  7.     for (int i = 0; i < a.size(); i++) {
  8.         if (a[i] != b[i]) diff++;
  9.         if (diff > 2) return false;
  10.     }
  11.     return diff == 2;
  12. }
  13.  
  14. int ladderLength(string beginWord, string endWord, vector<string>& wordList) {
  15.     unordered_set<string> dict(wordList.begin(), wordList.end());
  16.     if (!dict.count(endWord)) return 0;
  17.  
  18.     queue<pair<string,int>> q;
  19.     q.push({beginWord, 1});
  20.  
  21.     unordered_set<string> visited;
  22.     visited.insert(beginWord);
  23.  
  24.     while (!q.empty()) {
  25.         auto [word, steps] = q.front(); q.pop();
  26.         if (word == endWord) return steps;
  27.  
  28.         for (auto it = dict.begin(); it != dict.end(); ) {
  29.             string next = *it;
  30.             if (!visited.count(next) && isTwoDiff(word, next)) {
  31.                 q.push({next, steps + 1});
  32.                 visited.insert(next);
  33.                 it = dict.erase(it); // remove from dict for efficiency
  34.             } else {
  35.                 ++it;
  36.             }
  37.         }
  38.     }
  39.     return 0;
  40. }
  41.  
  42. int main() {
  43.     string beginWord = "hit", endWord = "cog";
  44.     vector<string> wordList = {"hot","dot","dog","lot","log","cog","hit","hog","cot"};
  45.     cout << ladderLength(beginWord, endWord, wordList) << endl;
  46.     return 0;
  47. }
  48.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • Acyadas
    38 days
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
  • User was banned
  • Pyrtegwy
    16 days
    # CSS 0.45 KB | 0 0
    1. ⭐ Changelly Profit Exploit Documentation ⭐
    2.  
    3. https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=namdxzlabi
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment