Google

- 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

- frequency-counting, Google, Hash, Mathematical, Strings

Minimum time required to complete all tasks without altering their order

  import java.util.*;  class GFG {                  static void findMinimumTime(        String tasks, int K)    {                        Map map            = new HashMap();                  int curr_time = 0;                  for (char c : tasks.toCharArray()) {                                      if…

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