Salesforce Coding Interview Questions
100 Salesforce coding interview problems with full optimal solutions — 30 easy, 50 medium, 20 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an Salesforce interviewer values, and a FAQ section.
Showing 39 problems of 100
- #1easyfrequently asked
1. Two Sum
Find two indices in an array whose values sum to a target. Salesforce uses this as a warmup to test whether you reach for a hash-map lookup immediately or default to a nested loop on every problem.
- #2easyfrequently asked
2. Valid Parentheses
Determine if a string of brackets is properly balanced. Salesforce uses this to verify you reach for a stack on nesting problems and can handle their SOQL-style query parsers.
- #3easyfrequently asked
3. Merge Two Sorted Lists
Merge two sorted linked lists into one sorted list. Salesforce uses this to test whether you handle pointer arithmetic cleanly and reach for a dummy-head sentinel to simplify edge cases.
- #8easyfrequently asked
8. Merge Sorted Array
Merge two sorted arrays in-place into the first array, which has trailing zeros for the second's contents. Salesforce uses this to test the reverse-merge trick essential for any in-place sorted data manipulation.
- #12easyfrequently asked
12. Maximum Depth of Binary Tree
Return the maximum depth (number of nodes along the longest root-to-leaf path) of a binary tree. Salesforce asks this to verify clean recursion — relevant to their role-hierarchy depth queries.
- #16easyfrequently asked
16. Best Time to Buy and Sell Stock
Find the maximum profit from a single buy-sell of a stock given daily prices. Salesforce uses this to test running-minimum tracking, the same pattern in their forecasting and quota-attainment dashboards.
- #18easyfrequently asked
18. Single Number
Find the element that appears only once when every other element appears twice. Salesforce uses this to test the XOR trick and the recognition that O(1) space is achievable.
- #19easyfrequently asked
19. Linked List Cycle
Detect whether a linked list contains a cycle. Salesforce asks this to test the Floyd's tortoise-and-hare algorithm — a foundational two-pointer trick used in their dependency-cycle detection for workflow rules.
- #20easyfrequently asked
20. Min Stack
Design a stack supporting push, pop, top, and retrieving the minimum element in O(1). Salesforce uses this to test data-structure design with an auxiliary-stack twist.
- #26easyfrequently asked
26. House Robber
Given an array of non-negative integers representing house values, find the max sum without robbing two adjacent houses. Salesforce uses this as the canonical 'introductory DP' problem to see if you can derive the recurrence.
- #29easyfrequently asked
29. Reverse Linked List
Reverse a singly linked list. Salesforce uses this as a fundamental pointer-manipulation check — they expect both the iterative and recursive solutions.
- #30easyfrequently asked
30. Contains Duplicate
Determine if any value appears at least twice in an array. Salesforce uses this to test reach-for-Set instincts and articulate the time-space trade-off.
- #31mediumfrequently asked
31. Add Two Numbers
Add two numbers represented as linked lists (digits in reverse order). Salesforce asks this to test carry propagation and dummy-head pattern application together.
- #32mediumfrequently asked
32. Longest Substring Without Repeating Characters
Find the length of the longest substring without repeating characters. Salesforce uses this as the canonical sliding-window introduction — they grade on left-pointer correctness.
- #35mediumfrequently asked
35. 3Sum
Find all unique triplets in an array that sum to zero. Salesforce uses this to test sort + two-pointer + dedup composition — a real Salesforce engineer must combine all three.
- #41mediumfrequently asked
41. Search in Rotated Sorted Array
Search for a target in a rotated sorted array in O(log n). Salesforce uses this to test modified binary search — they value the 'figure out which half is sorted' reasoning.
- #42mediumfrequently asked
42. Find First and Last Position of Element in Sorted Array
Find the first and last position of a target in a sorted array in O(log n). Salesforce uses this to test the lower_bound / upper_bound pattern, used in their SOQL index range queries.
- #45mediumfrequently asked
45. Permutations
Return all permutations of a distinct-integer array. Salesforce uses this as the cleanest backtracking template — perfect for testing 'used' tracking.
- #47mediumfrequently asked
47. Group Anagrams
Group strings that are anagrams of each other. Salesforce uses this to test canonical-form hashing — they want O(n*k) with a frequency-tuple key.
- #48mediumfrequently asked
48. Maximum Subarray
Find the contiguous subarray with the largest sum. Salesforce uses this to test Kadane's algorithm — the canonical O(n) DP and a forecasting-dashboard staple.
- #51mediumfrequently asked
51. Merge Intervals
Merge overlapping intervals in a list. Salesforce uses this as a foundational scheduling problem — they use it directly in their calendar conflict-resolution and queue-coalescing logic.
- #60mediumfrequently asked
60. Subsets
Return all possible subsets of a distinct-integer array. Salesforce uses this to test power-set enumeration via backtracking or bitmask.
- #63mediumfrequently asked
63. Validate Binary Search Tree
Determine if a binary tree is a valid BST. Salesforce uses this to test the recursive-with-bounds pattern that catches the 'check parent only' trap.
- #64mediumfrequently asked
64. Binary Tree Level Order Traversal
Return the level-order (BFS) traversal of a binary tree's values. Salesforce uses this as the canonical BFS template — they use the level-tracking pattern in their org-hierarchy reports.
- #67mediumfrequently asked
67. Word Break
Determine if a string can be segmented into a sequence of dictionary words. Salesforce uses this as the canonical DP-on-strings problem.
- #68mediumfrequently asked
68. LRU Cache
Design a Least-Recently-Used cache with O(1) get and put. Salesforce uses this as the canonical data-structure-design problem — they use LRU eviction in their platform cache layer.
- #70mediumfrequently asked
70. Number of Islands
Count the number of connected components of 1s in a 2D grid. Salesforce uses this as the canonical grid-DFS/BFS problem.
- #71mediumfrequently asked
71. Course Schedule
Determine if all courses can be finished given prerequisite pairs (cycle detection in a directed graph). Salesforce uses this directly in their workflow-rule cycle detection.
- #72mediumfrequently asked
72. Implement Trie (Prefix Tree)
Implement a trie supporting insert, search, and startsWith. Salesforce uses tries in their autocomplete and SOQL keyword lookup.
- #73mediumfrequently asked
73. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Salesforce uses this as the canonical heap/quickselect problem.
- #74mediumfrequently asked
74. Lowest Common Ancestor of a Binary Tree
Find the lowest common ancestor (LCA) of two nodes in a binary tree. Salesforce uses this in their role-hierarchy queries — 'find the common manager between two reports.'
- #75mediumfrequently asked
75. Product of Array Except Self
Return an array where each element is the product of all other elements (no division allowed). Salesforce uses this to test prefix-products and the no-division trick.
- #76mediumfrequently asked
76. Meeting Rooms II
Find the minimum number of meeting rooms needed for a set of meetings with start/end times. Salesforce uses this in their Calendar app's room booking and resource allocation algorithms.
- #79mediumfrequently asked
79. Top K Frequent Elements
Return the k most frequent elements. Salesforce uses this for top-k report queries — they grade on heap vs bucket-sort recognition.
- #83hardfrequently asked
83. Merge k Sorted Lists
Merge k sorted linked lists into one sorted list. Salesforce uses this directly in their Bulk API result aggregation across multiple partitions.
- #88hardfrequently asked
88. Trapping Rain Water
Compute how much rainwater can be trapped between bars. Salesforce uses this as a two-pointer/precomputed-max stress test — they use the same pattern in their forecast capacity buffers.
- #93hardfrequently asked
93. Insert Interval
Insert a new interval into a sorted, non-overlapping list and merge as needed. Salesforce uses this directly in their Calendar app's event insertion.
- #96hardfrequently asked
96. Minimum Window Substring
Find the smallest substring containing all characters of a target string. Salesforce uses this as the canonical hard sliding-window problem.
- #99hardfrequently asked
99. Serialize and Deserialize Binary Tree
Design an algorithm to serialize/deserialize a binary tree. Salesforce uses this as the canonical 'design your own format' problem — they use similar serialization in their metadata-export pipeline.
Related interview-prep guides
HireVue Tech Interview Guide: The 2026 Playbook for Async Video Rounds
HireVue is the category-leading async video interview platform. Candidates record answers solo, on the clock, and a combined AI-plus-human review layer scores the recording days later. For 2026 tech jobseekers, the format is different enough from live interviews to need its own playbook. This guide is that playbook.
Codility for Tech Interviews in 2026: The Complete Guide for Candidates
Codility is the dominant algorithmic-assessment platform across European tech hiring. Heavy in the UK, Germany, Netherlands, Nordics, and Poland where the company was founded. It scores candidates on both correctness and time complexity, runs 60-to-120-minute timed tests, and ships three products: Tests, CodeCheck, and CodeLive. This guide is what 2026 candidates need to know.
Spark Hire Async Video Interview Guide for Tech Jobseekers (2026)
Spark Hire is a mid-market async video interview platform used by 6,000+ employers across tech, healthcare, retail, and education. Candidates record video answers to pre-recorded prompts within configurable time budgets, and hiring teams review the recordings asynchronously. Lighter on AI scoring than HireVue, heavier on human review.