- cpp-stack, cpp-stack-functions, Data Structures, interview-preparation, Stack, System-Design

Design a dynamic stack using arrays that supports getMin() in O(1) time and O(1) extra space

#include using namespace std;  class Stack {private:            int Max = 5;              int* arr = new int(Max);              int minEle = 0;              int top = 0;  public:            bool empty()    {        if…

Read More

- Parentheses-Problems, Stack, Strings, Tree

Construct a Binary Tree from String with bracket representation | Set 2

  #include using namespace std;  struct Node {    Node* left;    Node* right;    int data;              Node(int element)    {        data = element;        this->left = nullptr;        this->right = nullptr;    }};  void preorder(Node* root){    if (!root)        return;      cout data…

Read More

- Google, Greedy, interview-preparation, Stack, Strings, substring

Maximize cost of removing all occurrences of substrings “ab” and “ba”

  import java.util.*;  class GFG {              public static int MaxCollection(        String S, int P, int Q)    {                        char maxstr[]            = (P >= Q ? “ab” : “ba”).toCharArray();                          char…

Read More

- Data Structures, interview-preparation, Microsoft, Stack

Check if two Stacks are equal or not without alteration

  import java.util.*;  class GFG {          static String compareStacks(        Stack s1,        Stack s2)    {                int N = s1.size();                  int M = s2.size();                  if (N != M) {            return “No”;        }                  for (int…

Read More