Salesforce logo

Salesforce Medium Interview Questions

6 medium-level practice questions for Salesforce technical interviews

Salesforce software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer

No verified questions yet for Salesforce.

coding Medium hash map #1

1. Hash Map — Counting occurrences of records

Background: In Salesforce's CRM system, it's crucial to understand the frequency of various record types in customer data analysis and reporting. An effective way to manage large datasets and derive insights requires efficient implementation of counting methods.
Problem statement: Given a list of customer records represented as strings, your task is to create a function that counts how many times each unique record appears in the list. The function should return a dictionary mapping each record to its count. For example: Given the input list ['Lead', 'Contact', 'Lead', 'Opportunity', 'Contact'], the output should be {'Lead': 2, 'Contact': 2, 'Opportunity': 1}.
Function/class signature:
  • def count_records(records: List[str]) -> Dict[str, int]:

Example 1: Input: ['Lead', 'Contact', 'Lead'] → Output: {'Lead': 2, 'Contact': 1} → Explanation: The record 'Lead' appears twice, while 'Contact' appears once.
Example 2: Input: ['Opportunity', 'Client', 'Client', 'Lead'] → Output: {'Opportunity': 1, 'Client': 2, 'Lead': 1} → Explanation: 'Client' appears twice, while both 'Opportunity' and 'Lead' appear once.
Constraints:
  • 1 <= records.length <= 10^5

  • Each record is a non-empty string

coding Medium hash map #2

2. HASH_MAP — Implement a simple inventory system using a hash map


Background: At Salesforce, managing customer inventories efficiently is crucial for CRM solutions. This problem involves storing and processing customer inventories to track items and quantities effectively.
Problem statement: You need to implement a simple inventory system where you can add items to inventory, update the quantities, and retrieve the current count of any item. Your inventory should be based on a hash map for quick access to item counts.
Function/class signature:
  • def add_item(item: str, quantity: int) -> None:

  • def update_item(item: str, quantity: int) -> None:

  • def get_count(item: str) -> int:


Example 1:
  • Input: add_item('Apples', 10)

  • Output: None

  • Explanation: The inventory now has 10 Apples.


Example 2:
  • Input: update_item('Apples', 5) followed by get_count('Apples')

  • Output: 15

  • Explanation: The total count of Apples is updated to 15.


Constraints:
  • The item string will be non-empty and contain at most 100 characters.

  • The quantity will be a positive integer not exceeding 1,000.


coding Medium dynamic programming #3

3. Dynamic Programming — Maximize Revenue from Sales

Background: Salesforce needs to analyze past customer purchase data to optimize sales strategies. This problem relates to their forecasting tools for sales teams.
Problem statement: Given an array of integers representing sales revenue from each day, your task is to calculate the maximum revenue that can be obtained on consecutive days without selling on two consecutive days. The revenue from any day can only be sold once.
Function/class signature:
  • def maximize_revenue(revenue: List[int]) -> int:


Example 1:
Input: revenue = [1, 2, 3, 1]
Output: 4
Explanation: You can sell on days 1 and 3 to get a maximum of 4.
Example 2:
Input: revenue = [2, 7, 9, 3, 1]
Output: 12
Explanation: You can sell on days 2, 4 and get a maximum of 12.
Constraints:
  • The length of the revenue array will be at least 1 and at most 100.

  • Each revenue value will be between 0 and 1000.
coding Medium graph #4

4. Graph — Shortest Path in Salesforce's User Connections

Background: In Salesforce, user connections can be represented as a graph where users are nodes and their connections as edges. Finding the shortest path is crucial for analyzing user engagement and interaction.
Problem statement: Given a directed graph represented as an adjacency list, write a function to find the shortest path from a given starting user to all other users. The graph can contain cycles, and users can be connected to themselves. Return a dictionary where each user is mapped to its shortest distance from the starting user.
Function/class signature:
  • def shortest_path(graph: Dict[str, List[str]], start: str) -> Dict[str, int]:

Example 1:
Input: graph = {'A': ['B'], 'B': ['C', 'D'], 'C': ['D'], 'D': []}, start = 'A'
Output: {'A': 0, 'B': 1, 'C': 2, 'D': 2}
Explanation: The shortest path from 'A' to 'B' is 1, to 'C' is 2, and to 'D' is also 2.
Example 2:
Input: graph = {'A': ['B', 'C'], 'B': ['C'], 'C': ['A'], 'D': []}, start = 'A'
Output: {'A': 0, 'B': 1, 'C': 1, 'D': inf}
Explanation: 'D' is unreachable from 'A', thus returns inf.
Constraints:
  • Nodes in the graph: 1 ≤ |V| ≤ 10^5

  • Edges in the graph: 0 ≤ |E| ≤ 10^5

  • Start node will always be present in the graph.

coding Medium two pointers #5

5. Two Pointers — Find Pair with Given Sum in Customer Data

1. Background: In Salesforce, analyzing customer interactions is crucial for understanding their needs and improving services. The platform often needs to identify customer pairs that meet certain criteria, such as joint subscriptions.
2. Problem statement: You are given an array of integers representing customer IDs and an integer target that represents a desired sum of IDs. Your task is to find two distinct customers such that their IDs sum up to the target. Return the indices of these two customers in an array. If no such pair exists, return an empty array.
3. Function/class signature:
- def findCustomerPair(customer_ids: List[int], target: int) -> List[int]:
4. Example 1:
Input: customer_ids = [2, 7, 11, 15], target = 9
Output: [0, 1]
Explanation: Customer IDs 2 and 7 add up to 9.
5. Example 2:
Input: customer_ids = [3, 5, 2, 8], target = 10
Output: [0, 3]
Explanation: Customer IDs 3 and 7 add up to 10.
6. Constraints:
- 2 <= len(customer_ids) <= 10^4
- -10^9 <= customer_ids[i] <= 10^9
- -10^9 <= target <= 10^9
coding Medium cache #6

6. CODING — Implement an LRU Cache

Background: In Salesforce, optimizing performance for frequently accessed data is critical, especially for applications dealing with large customer datasets. An LRU (Least Recently Used) Cache can help in efficiently managing memory by storing a limited number of data entries.
Problem statement: Design an LRUCache class that supports the following methods: get(key: int) -> int which retrieves the value of the key if the key exists in the cache, otherwise returns -1. The put(key: int, value: int) -> None method will insert a new key-value pair in the cache. If the number of keys exceeds the capacity, it should invalidate the least recently used key before inserting the new key.
Function/class signature:
  • def get(self, key: int) -> int:

  • def put(self, key: int, value: int) -> None:

Example 1:
  • Input: cache = LRUCache(2)

cache.put(1, 1)
cache.put(2, 2)
cache.get(1)
  • Output: 1

  • Explanation: The cache now contains two items: (1,1) and (2,2).

Example 2:
  • Input:

cache.put(3, 3)
cache.get(2)
  • Output: -1

  • Explanation: The cache reached its capacity and evicted key 2.

Constraints:
  • 1 <= capacity <= 3000

  • 0 <= key <= 10^4

  • 0 <= value <= 10^4

  • Function calls will occur at most 10^4 times.

Start practicing Salesforce questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free