Wednesday, 1 Dec 2021
Category: deque

#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) […]

Given an array arr[] of N integers, the task is to find the lexicographically largest permutation by sequentially inserting the array elements to the front or the back of another array.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and […]

Reduce the given Array of [1, N] by rotating left or right based on given conditionsGiven a sorted array arr[] of the first N Natural Numbers and an integer X, the task is to print the last remaining element after performing the below operations (N – 1) times:Examples:Input: N = 5, arr[] = {1, 2, […]

#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; […]

Length of all prefixes that are also the suffixes of given string Given a string S consisting of N characters, the task is to find the length of all prefixes of the given string S that are also suffixes of the same string S.Examples:Input: S = “ababababab”Output: 2 4 6 8Explanation: The prefixes of S that […]