Saturday, 4 Dec 2021
Category: interview-preparation

#include using namespace std;  void printGalaxy(    vector mat, int n){          for (int i = 0; i < n; i++) {                          if (mat[0][i] == '#'            && mat[1][i] == '#'            && mat[2][i] == '#') {            cout

Given an integer, instances, and an array, arr[] of size N representing the average utilization percentage of the computing system at each second, the task is to find the number of instances at the end of the time frame such that the computing system auto-scales the number of instances according to the following rules: Average utilization […]

#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 (top

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 = 0; i < N; i++) {                                                  int y = countGreater(                arr2, arr1[i]);                          res += y;        }                          res = (double)res / (double)(N * M);                  return res;    }                  static int countGreater(int[] arr,                            int k)    {        int n = arr.length;        int l = 0;        int r = n - 1;                                  int leftGreater […]

#include using namespace std;  class Node {public:    int data;    Node* next;};  Node* newNode(int data){        Node* new_node = new Node;    new_node->data = data;    new_node->next = NULL;          return new_node;}  int subtractOneUtil(Node* head){          if (head == NULL)        return -1;              int borrow = subtractOneUtil(        head->next);          if (borrow == -1) {                          if (head->data == 0) {            head->data = 9;            return -1;        }                          else {            head->data = head->data – 1;            return 0;        }    }          else {        return 0;    }}  Node* subtractOne(Node* head){              subtractOneUtil(head);              while (head and head->next           and head->data == 0) […]

import java.util.*;import java.lang.*;  class GFG {              static int minTime(int[] A, int n, int K)    {                int max_ability = A[0];                  for (int i = 1; i < n; i++) {            max_ability = Math.max(                max_ability, A[i]);        }                  int tmp[] = new int[max_ability + 1];                          int count = 0;                  for (int i = 0; i < n; i++) {            tmp[A[i]]++;        }                  for (int i = max_ability;             i >= 0; i–) {              if (tmp[i] != […]