Meta | Phone Screen | Custom Sort String and Minimum Flight Cost
Anonymous User
1289

I had my Meta phone screen round recently. I was asked the below 2 questions:

  1. 791 Custom Sort String https://leetcode.com/problems/custom-sort-string/description/
public String customSortString(String order, String s) {
      Map<Character, Integer> map = new HashMap<>();
      int n = s.length();
      int m = order.length();
      
      for(int i=0; i<n; i++)
        {
          char letter = s.charAt(i);
          map.put(letter, map.getOrDefault(letter,0)+1);
        }

      StringBuilder result = new StringBuilder();

      for(int i =0; i<m; i++)
        {
          char letter = order.charAt(i);
          if(map.containsKey(letter))
          {
            int count = map.get(letter);
            while(count-- > 0)
              {
                result.append(letter);
                map.put(letter,count);
              }
          }
        }

      for(char key : map.keySet())
        {
          int count = map.get(key);
          while(count > 0)
            {
              result.append(key);
              count--;
            }
        }
      return result.toString();
    }
  1. Plan a round trip between 2 cities with minimum flight cost. Given 2 arrays - Deprature costs and Return Costs. Both arrays will always have same size. D =[10,8,9,11,7] R =[8,8,10,7,9] ; Ans = 15 (8+7) ; Note: It cannot be 7+7 as you can't take return flight without taking departure flight.
public static int minFlightCost(int[] D, int[] R) {
        int n = D.length;
        int minDep = Integer.MAX_VALUE;
        int minRT = Integer.MAX_VALUE;

        for (int i = 0; i < n; i++) {
            if (i > 0) {
                minRT = Math.min(minRT, minDep + R[i]);
            }
            minDep = Math.min(minDep, D[i]);
        }
        return minRT;
    }

Interview Format: It is a 45 mins round set for 2 programming questions only.
I was asked the time and space complexity with justifications and to walk through the code with an example, also the edge cases and how will they be handled.

Also, can anyone with experience share me to the onsite round format, tips and typical questions to practice please?

Comments (2)