interview-preparation

- 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

- Arrays, Binary Search, Google, Greedy, interview-preparation, Mathematical, Probability, Searching, Sorting

Probability of obtaining pairs from two arrays such that element from the first array is smaller than that of the second array

  import java.util.*;  class GFG {                  static double probability(int[] arr1,                              int[] arr2)    {                int N = arr1.length;                  int M = arr2.length;                  double res = 0;                          Arrays.sort(arr2);                  for (int i =…

Read More