- 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