interview-preparation

- 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

- Amazon, Backtracking, Hash, interview-preparation, Mathematical, Strings

Convert a Mobile Numeric Keypad sequence to equivalent sentence

import java.io.*;import java.lang.*;import java.util.*;public class GFG {                static void printSentence(String S)    {                String nums[]            = { “”,    “”,    “ABC”,  “DEF”, “GHI”,                “JKL”, “MNO”, “PQRS”, “TUV”,…

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