Problem database last updated: June 20, 2025

SSalesforce logo

Salesforce Coding Interview Questions

94 problems · 14 Easy, 60 Medium, 20 Hard · Ranked #22 of 458

Difficulty breakdown

14 Easy

15% · avg 23%

60 Medium

64% · avg 59%

20 Hard

21% · avg 18%

Top topics

array
59.6%
string
29.8%
dynamic-programming
27.7%
hash-table
24.5%
sorting
21.3%1.5x
two-pointers
16%

Interview profile

Based on 94 reported problems, Salesforce interviews are in line with industry averages - 21% Hard vs 18% overall. The majority (64%) of questions are Medium difficulty, which is typical for companies that want to see solid fundamentals without excessive trick questions.

Compared to the industry average, Salesforce puts unusual emphasis on bitmask (2.1% of problems, 3.9x the industry average), ordered-set (3.2% of problems, 3.2x the industry average), data-stream (2.1% of problems, 3.2x the industry average). If you're short on time, these are the categories to double down on.

The most common topics are array (59.6%), string (29.8%), dynamic-programming (27.7%), hash-table (24.5%). Problems below are sorted by frequency, the ones at the top are asked most often.

All 94 problems

Word Break

Solve

Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

MediumVery Likely
arrayhash-tablestring

Subarray Product Less Than K

Solve

Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly le...

MediumVery Likely
arraybinary-searchsliding-window

String Compression

Solve

Given an array of characters chars, compress it using the following algorithm:

MediumVery Likely
two-pointersstring

Distinct Subsequences

Solve

Given two strings s and t, return the number of distinct subsequences of s which equals t.

HardVery Likely
stringdynamic-programming

LFU Cache

Solve

Design and implement a data structure for a Least Frequently Used (LFU) cache.

HardVery Likely
hash-tablelinked-listdesign

Merge Intervals

Solve

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cove...

MediumVery Likely
arraysorting

LRU Cache

Solve

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

MediumVery Likely
hash-tablelinked-listdesign

Group Anagrams

Solve

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

MediumVery Likely
arrayhash-tablestring

Number of Islands

Solve

Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

MediumVery Likely
arraydepth-first-searchbreadth-first-search

Count the Number of Fair Pairs

Solve

Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.

MediumLikely
arraytwo-pointersbinary-search

Maximum Frequency Stack

Solve

Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack.

HardLikely
hash-tablestackdesign

Height Checker

Solve

A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let thi...

EasyLikely
arraysortingcounting-sort

Design a Text Editor

Solve

Design a text editor with a cursor that can do the following:

HardLikely
linked-liststringstack

Palindromic Substrings

Solve

Given a string s, return the number of palindromic substrings in it.

MediumLikely
two-pointersstringdynamic-programming

Longest Substring Without Repeating Characters

Solve

Given a string s, find the length of the longest substring without duplicate characters.

MediumLikely
hash-tablestringsliding-window

Beautiful Towers II

Solve

You are given a 0-indexed array maxHeights of n integers.

MediumLikely
arraystackmonotonic-stack

Course Schedule II

Solve

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, b...

MediumLikely
depth-first-searchbreadth-first-searchgraph

Beautiful Towers I

Solve

You are given an array heights of n integers representing the number of bricks in n consecutive towers. Your task is to remove some bricks to form a mountain-sh...

MediumLikely
arraystackmonotonic-stack

Check Whether Two Strings are Almost Equivalent

Solve

Two strings word1 and word2 are considered almost equivalent if the differences between the frequencies of each letter from 'a' to 'z' between word1 and word2 i...

EasyLikely
hash-tablestringcounting

Best Time to Buy and Sell Stock

Solve

You are given an array prices where prices[i] is the price of a given stock on the ith day.

EasyLikely
arraydynamic-programming

Valid Parentheses

Solve

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

EasyLikely
stringstack

Split Array Largest Sum

Solve

Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.

HardLikely
arraybinary-searchdynamic-programming

Trapping Rain Water

Solve

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

HardLikely
arraytwo-pointersdynamic-programming

Beautiful Arrangement

Solve

Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i...

MediumLikely
arraydynamic-programmingbacktracking

Kth Largest Element in an Array

Solve

Given an integer array nums and an integer k, return the kth largest element in the array.

MediumLikely
arraydivide-and-conquersorting

Binary Tree Maximum Path Sum

Solve

A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequ...

HardLikely
dynamic-programmingtreedepth-first-search

Largest Number

Solve

Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.

MediumLikely
arraystringgreedy

Maximum Product of Three Numbers

Solve

Given an integer array nums, find three numbers whose product is maximum and return the maximum product.

EasyLikely
arraymathsorting

Asteroid Collision

Solve

We are given an array asteroids of integers representing asteroids in a row. The indices of the asteroid in the array represent their relative position in space...

MediumLikely
arraystacksimulation

Integer to Roman

Solve

Seven different symbols represent Roman numerals with the following values:

MediumLikely
hash-tablemathstring

3Sum

Solve

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

MediumLikely
arraytwo-pointerssorting

Task Scheduler

Solve

You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task....

MediumLikely
arrayhash-tablegreedy

Longest Palindromic Substring

Solve

Given a string s, return the longest palindromic substring in s.

MediumLikely
two-pointersstringdynamic-programming

Coin Change

Solve

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

MediumLikely
arraydynamic-programmingbreadth-first-search

Count Palindromic Subsequences

Solve

Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 109 + 7.

HardLikely
stringdynamic-programming

Minimum Window Substring

Solve

Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is inc...

HardLikely
hash-tablestringsliding-window

Min Stack

Solve

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

MediumLikely
stackdesign

Validate Binary Search Tree

Solve

Given the root of a binary tree, determine if it is a valid binary search tree (BST).

MediumLikely
treedepth-first-searchbinary-search-tree

Top K Frequent Elements

Solve

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

MediumLikely
arrayhash-tabledivide-and-conquer

Decode Ways

Solve

You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping:

MediumLikely
stringdynamic-programming

Maximal Square

Solve

Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

MediumLikely
arraydynamic-programmingmatrix

Partition Array Into Two Arrays to Minimize Sum Difference

Solve

You are given an integer array nums of 2 n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of t...

HardSometimes
arraytwo-pointersbinary-search

Jump Game

Solve

You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length...

MediumSometimes
arraydynamic-programminggreedy

Decode String

Solve

Given an encoded string, return its decoded string.

MediumSometimes
stringstackrecursion

Search in Rotated Sorted Array

Solve

There is an integer array nums sorted in ascending order (with distinct values).

MediumSometimes
arraybinary-search

Daily Temperatures

Solve

Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait aft...

MediumSometimes
arraystackmonotonic-stack

Reconstruct Original Digits from English

Solve

Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.

MediumSometimes
hash-tablemathstring

Is Subsequence

Solve

Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

EasySometimes
two-pointersstringdynamic-programming

Combination Sum

Solve

Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum...

MediumSometimes
arraybacktracking

Max Area of Island

Solve

You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume al...

MediumSometimes
arraydepth-first-searchbreadth-first-search

Container With Most Water

Solve

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).

MediumSometimes
arraytwo-pointersgreedy

Capacity To Ship Packages Within D Days

Solve

A conveyor belt has packages that must be shipped from one port to another within days days.

MediumSometimes
arraybinary-search

Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increa...

HardSometimes
arraygreedysorting

Count Binary Substrings

Solve

Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings...

EasySometimes
two-pointersstring

Degree of an Array

Solve

Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.

EasySometimes
arrayhash-table

Product of Array Except Self

Solve

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

MediumSometimes
arrayprefix-sum

Maximize Greatness of an Array

Solve

You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.

MediumSometimes
arraytwo-pointersgreedy

Populating Next Right Pointers in Each Node

Solve

You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:

MediumSometimes
linked-listtreedepth-first-search

House Robber

Solve

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from rob...

MediumSometimes
arraydynamic-programming

Roman to Integer

Solve

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

EasySometimes
hash-tablemathstring

Pow(x, n)

Solve

Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

MediumSometimes
mathrecursion

Construct Binary Tree from Preorder and Inorder Traversal

Solve

Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, c...

MediumSometimes
arrayhash-tabledivide-and-conquer

First Missing Positive

Solve

Given an unsorted integer array nums. Return the smallest positive integer that is not present in nums.

HardSometimes
arrayhash-table

Merge k Sorted Lists

Solve

You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.

HardSometimes
linked-listdivide-and-conquerheap-priority-queue

Wildcard Matching

Solve

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '' where:

HardSometimes
stringdynamic-programminggreedy

Find Median from Data Stream

Solve

The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two midd...

HardSometimes
two-pointersdesignsorting

Move Zeroes

Solve

Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.

EasySometimes
arraytwo-pointers

Rotting Oranges

Solve

You are given an m x n grid where each cell can have one of three values:

MediumSometimes
arraybreadth-first-searchmatrix

Lowest Common Ancestor of a Binary Tree

Solve

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

MediumSometimes
treedepth-first-searchbinary-tree

Maximum Difference Between Increasing Elements

Solve

Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and...

EasySometimes
array

Serialize and Deserialize Binary Tree

Solve

Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitte...

HardSometimes
stringtreedepth-first-search

Kth Smallest Element in a Sorted Matrix

Solve

Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix.

MediumSometimes
arraybinary-searchsorting

Smallest Subtree with all the Deepest Nodes

Solve

Given the root of a binary tree, the depth of each node is the shortest distance to the root.

MediumSometimes
hash-tabletreedepth-first-search

2 Keys Keyboard

Solve

There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step:

MediumSometimes
mathdynamic-programming

Flatten Binary Tree to Linked List

Solve

Given the root of a binary tree, flatten the tree into a "linked list":

MediumSometimes
linked-liststacktree

The Skyline Problem

Solve

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of...

HardSometimes
arraydivide-and-conquerbinary-indexed-tree

Minimum Path Sum

Solve

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.

MediumSometimes
arraydynamic-programmingmatrix

Pairs of Songs With Total Durations Divisible by 60

Solve

You are given a list of songs where the ith song has a duration of time[i] seconds.

MediumSometimes
arrayhash-tablecounting

Best Time to Buy and Sell Stock II

Solve

You are given an integer array prices where prices[i] is the price of a given stock on the ith day.

MediumSometimes
arraydynamic-programminggreedy

Different Ways to Add Parentheses

Solve

Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. Y...

MediumSometimes
mathstringdynamic-programming

Insert Delete GetRandom O(1)

Solve

Implement the RandomizedSet class:

MediumSometimes
arrayhash-tablemath

N-Queens

Solve

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

HardSometimes
arraybacktracking

Stream of Characters

Solve

Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings words.

HardSometimes
arraystringdesign

Triangle

Solve

Given a triangle array, return the minimum path sum from top to bottom.

MediumSometimes
arraydynamic-programming

Longest Valid Parentheses

Solve

Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.

HardSometimes
stringdynamic-programmingstack

Sort Colors

Solve

Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order...

MediumSometimes
arraytwo-pointerssorting

Number of Matching Subsequences

Solve

Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.

MediumSometimes
arrayhash-tablestring

Subsets

Solve

Given an integer array nums of unique elements, return all possible subsets (the power set).

MediumSometimes
arraybacktrackingbit-manipulation

Majority Element II

Solve

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.

MediumSometimes
arrayhash-tablesorting

Count Primes

Solve

Given an integer n, return the number of prime numbers that are strictly less than n.

MediumSometimes
arraymathenumeration

Majority Element

Solve

Given an array nums of size n, return the majority element.

EasySometimes
arrayhash-tabledivide-and-conquer

Predict the Winner

Solve

You are given an integer array nums. Two players are playing a game with this array: player 1 and player 2.

MediumSometimes
arraymathdynamic-programming

Isomorphic Strings

Solve

Given two strings s and t, determine if they are isomorphic.

EasySometimes
hash-tablestring

Reverse Words in a String III

Solve

Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

EasySometimes
two-pointersstring

How often are these problems asked?

Frequency scores are based on crowdsourced interview reports. A higher score means the problem has been reported more often in recent Salesforce interviews.

Very Likely

75-100%

Likely

50-74%

Sometimes

25-49%

Rare

0-24%

Preparing for your Salesforce coding interview

Salesforce interviews focus heavily on array, string, dynamic-programming problems. If you're short on time, these are the categories to prioritize. The problems on this page are sorted by frequency, so start from the top and work your way down.

Beyond solving problems, practice explaining your approach. Salesforce interviewers care about your thought process - how you break down a problem, consider edge cases, and evaluate tradeoffs between solutions. A clean O(n) solution you can explain clearly beats an O(log n) solution you can't articulate.

Looking for more companies? Browse all 458 companies in our directory, or sharpen your fundamentals with our free data structure visualizers and AI-powered DSA tutor.

Frequently Asked Questions

What coding problems does Salesforce ask in interviews?add

Salesforce has been reported to ask 94 distinct coding problems. The most common topics are array, string, dynamic-programming. 14 are Easy difficulty, 60 are Medium, and 20 are Hard. Problems are sorted by frequency - the ones at the top are asked most often.

How hard are Salesforce coding interviews?add

Based on 94 reported problems, Salesforce interviews are in line with industry averages - 21% Hard vs 18% overall. 64% of questions are Medium difficulty. Focus on the high-frequency Medium problems first, then work through the Hard ones.

How should I prepare for a Salesforce coding interview?add

Start with the highest-frequency problems listed on this page. Focus on the core topics: array, string, dynamic-programming. Practice solving them under time pressure and explaining your approach out loud. Mock interviews with AI can simulate the real experience.

Other companies to explore

Ready to ace your Salesforce interview?

Simulate a real Salesforce coding interview with an AI interviewer. Get a scorecard with specific feedback on your problem-solving, code quality, and communication.

Simulate a Salesforce interview with AIarrow_forward