Category: interview-preparation

TCS CodeVita 9 ( Zone 1) 2020 | Constellation

#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

Continue Reading

Find instances at end of time frame after auto scaling

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

Continue Reading

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 = 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 […]

Continue Reading

Subtract 1 from a number represented as Linked List

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

Continue Reading

Minimum time required to schedule K processes

  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] != […]

Continue Reading