Category: deque

Minimum number of deques required to make the array sorted

#include using namespace std;int minDeques(vector arr){            vector fronts, backs;        for (int i = 0; i < arr.size(); i++) {                        bool hasBeenPushed = false;        for (int j = 0; j < fronts.size(); j++) {                                    if (arr[i] < fronts[j]) {                bool isSafe = true;                for (int k = 0; k < arr.size(); k++) {                    if (arr[i] < arr[k]                        && arr[k] < fronts[j]) {                        isSafe = false;                        break;                    }                }                                                if (isSafe) […]

Continue Reading

Check if given Strings can be made equal by inserting at most 1 String

#include using namespace std;  bool areSimilar(string S1, string S2){        int N = S1.size();          int M = S2.size();              if (N == M) {                        if (S1 == S2)            return true;                  return false;    }          deque X, Y;                  S1.push_back(‘ ‘);    S2.push_back(‘ ‘);      string temp = “”;          for (int i = 0; i < N + 1; i++) {                                  if (S1[i] == ' ') {            X.push_back(temp);            temp = "";        }        else {                                    temp += S1[i];        }    }          for (int i = 0; […]

Continue Reading