Panda Guru LogoPanda
Guru

Salesforce Interview Experience.

Round 1

Questions:

  1. Tool List
    A milling machine in a manufacturing facility has a tool change system. The tool changer holds n tools and some duplicate tools may be included. The operator must move through the tools one at a time, either moving left or right. The tool changer is circular, so when the last tool in the tools array is reached in either direction, the next tool is at the other end of the array.
    Given the name of the next tool needed, determine the minimum number of left or right moves to reach it.
    Example:

    tools = ['ballendmill', 'keywaycutter', 'slotdrill', 'facemill'] startIndex = 1 target = 'ballendmill'

    The tool currently in use is keywaycutter at index 1. The desired tool is ballendmill at index 0. It can be reached by moving right 3 steps or left 1 step. The minimum number of moves is 1.
    Function Description: Complete the function toolchanger in the editor below.
    toolchanger has the following parameter(s):

    • str tools[n]: an array of tool names arranged in the order they appear in the tool changer
    • int startIndex: index of the tool currently in use
    • str target: name of the tool needed
  2. Horizontal Pod Autoscaler
    Description:
    The developers are trying to optimize their horizontal pod autoscaler for their micro-services. There are n micro-services where the number of pods for the ith micro-service is pods[i]. According to traffic, the number of pods of a service can increase or decrease. Also, at specific times when there is expected traffic, all services with fewer than x pods are assigned x pods.
    There is an event log of size m, which is described as a 2D array logs where logs[i] is an array of integers of size = 3. The interpretation of these logs are shown.

    • [1, p, x]: the number of pods of the pth micro-service is changed to x (1 ≤ p ≤ n).

    Code:

    def findPodCount(pods, logs): # Write your code here n = len(pods) last_u = [-1] * n mx = [0] * len(logs) for i, log in enumerate(logs): op, p, x = log if op == 1: idx = p - 1 pods[idx] = x last_u[idx] = i elif op == 2: mx[i] = x for i in range(len(logs) - 2, -1, -1): mx[i] = max(mx[i], mx[i + 1]) g_val = max(mx) for i in range(n): if last_u[i] == -1: pods[i] = max(pods[i], g_val) else: pods[i] = max(pods[i], mx[last_u[i]]) return pods
  3. Check the Structure
    Description:
    A binary tree uses a multi-node data structure where each node may have 0 to 2 child nodes, and has one stored value, its node number in this case. A tree may either be:

    • An empty tree, the root is null.
    • A non-empty tree with a non-null root node that contains a value and up to 2 subtrees, left and right, which are also binary trees.
      A binary tree is classified as a binary search tree (BST) if all of the non-null nodes exhibit two properties:
    • The left subtree of each node contains only nodes with values that are lower than its own value.
    • The right subtree of each node contains only nodes with values that are higher than its own value.
      A pre-order traversal is a recursive tree traversal method where the current node is visited first, then the left subtree, and then the right subtree. The following pseudocode parses a tree into a list using pre-order traversal:
    • If the root is null, return the null list.
    • For a non-null root node:
      1. Create a pre-order traversal list, left, of the left subtree.
      2. Create a pre-order traversal list, right, of the right subtree.
      3. Return the concatenated list: the non-null node + left + right.
  4. Long Encoded String
    Description:
    Consider a string that consists of lowercase English letters (i.e., [a-z]) only. The following rules are used to encode all of its characters into the string s.

    • a is encoded as 1, b is encoded as 2, c is encoded as 3, ..., and i is encoded as 9.
    • j is encoded as 10#, k is encoded as 11#, l is encoded as 12#, ..., and z is encoded as 26#.
      If any character occurs two or more consecutively, its count immediately follows the encoded character in parentheses, e.g. 'aa' is encoded as '1(2)'.
      Examples:
    • String "abzx" is encoded as s = "1226#24#".
    • String "aabccc" is encoded as s = "1(2)23(3)".
    • String "bajj" is encoded as s = "2110#(2)".
    • String "wwxyzwww" is encoded as s = "23#(2)24#25#26#23#(3)".
      Given an encoded string s, determine the character counts for each letter of the original, decoded string. Return an array of 26 integers where index 0 contains the number of 'a' characters, index 1 contains the number of 'b' characters, and so on.
      Function Description: Complete the frequency function in the editor below.
      frequency has the following parameter:
    • string s: an encoded string
      Return:
    • int[26]: the character frequencies as described
Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.