InternDoor

Salesforce interview prep

13 practice questions on the topics candidates reported from Salesforce interviews, with answers. The questions are ours; each one links to the interview report that names its topic.

Practise them as a timed round5 roles open at SalesForce-ad

DSA 9

  1. DSAEasy

    Which data structure is the natural fit for checking whether brackets like ([]{}) are balanced?

    1. A stack
    2. A queue
    3. A hash set
    4. A binary search tree
    Show the answer

    A. A stack

    Push each opening bracket. Each closing bracket must match the bracket on top, which is popped. The string is balanced if every bracket matched and the stack ends empty.

    This topic is named in a candidate’s interview report: Futureforce SWE intern on-campus interview, 2021, on GeeksforGeeks.

  2. DSAMedium

    To find the k-th largest of n numbers, you scan them while keeping a min-heap of at most k elements. What does this cost, and where is the answer at the end?

    1. O(n log n); it is the largest element in the heap
    2. O(n log k); it is the smallest element in the heap, at its top
    3. O(k log n); it is the last element pushed
    4. O(n); it is in the middle of the heap
    Show the answer

    B. O(n log k); it is the smallest element in the heap, at its top

    Each number costs O(log k): push it, and pop the minimum when the heap exceeds k. The heap then holds the k largest numbers, and the smallest of those, at the top, is the k-th largest.

    This topic is named in a candidate’s interview report: Technical support engineer intern on-campus interview, 2023, on GeeksforGeeks.

  3. DSAEasy

    A grid maze has open cells and walls. Which approach tells you whether the cheese can be reached from the start?

    1. Sort the cells by row
    2. A depth-first or breadth-first search from the start over open neighbouring cells, marking each cell visited
    3. Binary search over the rows
    4. Dijkstra's algorithm with negative weights
    Show the answer

    B. A depth-first or breadth-first search from the start over open neighbouring cells, marking each cell visited

    Reachability is a graph search: each open cell is a node joined to its open neighbours. Marking cells visited keeps it O(rows x columns). BFS also gives the shortest path length.

    This topic is named in a candidate’s interview report: Intern on-campus interview, 2023, on GeeksforGeeks.

  4. DSAMedium

    Kadane's algorithm finds the maximum sum of a contiguous subarray. For [-2, 1, -3, 4, -1, 2, 1, -5, 4], what is that sum and which indices does it cover?

    1. 6, indices 3 to 6
    2. 7, indices 3 to 8
    3. 5, indices 0 to 6
    4. 4, index 3 only
    Show the answer

    A. 6, indices 3 to 6

    Keep the best sum ending at each index: extend the previous run if it is positive, otherwise start again. The best run is 4, -1, 2, 1 at indices 3 to 6, summing to 6, in one O(n) pass.

    This topic is named in a candidate’s interview report: Technical support engineer intern on-campus interview, 2023, on GeeksforGeeks.

  5. DSAHard

    Numbers arrive one at a time and you must report the median after each. What gives O(log n) per insert and O(1) per median?

    1. Two heaps: a max-heap of the smaller half and a min-heap of the larger half, kept within one element of each other in size
    2. Keep a sorted array and insert each number in place
    3. A hash set of the numbers seen
    4. Sort everything again after each number
    Show the answer

    A. Two heaps: a max-heap of the smaller half and a min-heap of the larger half, kept within one element of each other in size

    The median is the top of the bigger heap, or the average of both tops when the sizes match. Each new number goes into one heap and at most one top moves across to rebalance, both O(log n). A sorted array needs O(n) shifting per insert.

    This topic is named in a candidate’s interview report: Futureforce SWE intern on-campus interview, 2021, on GeeksforGeeks.

  6. DSAMedium

    A sorted array is too long to know its length, but reading an index past the end is allowed and returns infinity. How do you find a key in O(log p), where p is the key's position?

    1. Scan from the start until you find it
    2. Binary search between 0 and the largest possible int
    3. Double a bound (1, 2, 4, 8, ...) until a[bound] >= key, then binary search between bound/2 and bound
    4. Hash every element first
    Show the answer

    C. Double a bound (1, 2, 4, 8, ...) until a[bound] >= key, then binary search between bound/2 and bound

    This is exponential (galloping) search. Doubling reaches past position p in about log p steps, and the binary search inside that last window takes about log p more. Searching up to the largest int would also work but costs log of that bound, not of p.

    This topic is named in a candidate’s interview report: Futureforce SWE intern on-campus interview, 2021, on GeeksforGeeks.

  7. DSAEasy

    How many distinct permutations does the string "aabc" have?

    1. 24
    2. 8
    3. 6
    4. 12
    Show the answer

    D. 12

    4 letters give 4! = 24 orders, but swapping the two a's gives the same string, so divide by 2! = 2: 12. In general n! divided by the factorial of each letter's count. Generating them by backtracking takes O(n * n!) time.

    This topic is named in a candidate’s interview report: SE summer intern on-campus interview, 2022, on GeeksforGeeks.

  8. DSAHard

    What is the length of the longest valid (well-formed) parentheses substring in ")()())"?

    1. 4
    2. 2
    3. 6
    4. 3
    Show the answer

    A. 4

    The valid part is "()()" at positions 1 to 4. A stack of indexes, starting with -1, finds it: push on "(", pop on ")", and after a pop the length is i minus the index now on top. The last ")" has nothing to match, so 6 is impossible.

    This topic is named in a candidate’s interview report: SE summer intern on-campus interview, 2022, on GeeksforGeeks.

  9. DSAHard

    Each row of an R x C binary matrix is sorted, 0s then 1s. Which method finds the row with the most 1s fastest in the worst case?

    1. Count every cell: O(R*C)
    2. Binary search each row for its first 1: O(R*C)
    3. Start at the top-right corner: step left while you see a 1, step down on a 0; O(R + C)
    4. Sort the rows by their sums: O(R log R)
    Show the answer

    C. Start at the top-right corner: step left while you see a 1, step down on a 0; O(R + C)

    Moving left means this row has more 1s than any before it, so remember it; moving down skips a row that cannot beat the best. Each step leaves a row or a column for good, so at most R + C steps. Binary search per row is O(R log C), better than counting but worse than the staircase.

    This topic is named in a candidate’s interview report: SDE intern on-campus interview, 2021, on GeeksforGeeks.

OOP 2

  1. OOPMedium

    What does "favour composition over inheritance" advise?

    1. Build behaviour by holding other objects that do part of the work, rather than by extending classes
    2. Never use inheritance at all
    3. Put every class in its own file
    4. Use interfaces only for constants
    Show the answer

    A. Build behaviour by holding other objects that do part of the work, rather than by extending classes

    Inheritance ties a subclass to its parent's internals and is fixed when compiled. Holding a collaborator, such as a Logger or a PricingRule, keeps classes loosely coupled and lets the part be swapped.

    This topic is named in a candidate’s interview report: SDE intern on-campus interview, 2021, on GeeksforGeeks.

  2. OOPEasy

    What is the difference between inheritance and composition?

    1. They are the same thing
    2. Inheritance models an is-a relationship (a Car is a Vehicle); composition models a has-a relationship by holding other objects as fields (a Car has an Engine)
    3. Composition is only possible in C++
    4. Inheritance copies the parent's objects; composition copies its methods
    Show the answer

    B. Inheritance models an is-a relationship (a Car is a Vehicle); composition models a has-a relationship by holding other objects as fields (a Car has an Engine)

    Composition keeps classes loosely coupled: the engine can be swapped or mocked, and changes inside it do not ripple into Car. Inheritance ties the child to the parent's implementation, which is why "favour composition over inheritance" is common advice.

    This topic is named in a candidate’s interview report: SDE intern on-campus interview, 2021, on GeeksforGeeks.

Web development 1

  1. Web developmentEasy

    What is a single-page application (SPA)?

    1. A website that has only one page of content
    2. A site served from a single server
    3. A page with no JavaScript
    4. An app that loads one HTML page and then redraws the view in JavaScript as the user moves around, fetching data rather than whole pages
    Show the answer

    D. An app that loads one HTML page and then redraws the view in JavaScript as the user moves around, fetching data rather than whole pages

    React, Angular and Vue apps are typically SPAs: the router changes the URL with the History API and swaps components without a full reload. The cost is a heavier first load and extra work for search engines, which server rendering addresses.

    This topic is named in a candidate’s interview report: SDE intern on-campus interview, 2024, on GeeksforGeeks.

Aptitude 1

  1. AptitudeMedium

    Of 12 identical-looking coins, one is fake and lighter. With a balance scale, what is the fewest weighings that always finds it?

    1. 2
    2. 4
    3. 3
    4. 6
    Show the answer

    C. 3

    Each weighing has three outcomes (left lighter, right lighter, balance), so k weighings can tell apart at most 3^k coins. 3^2 = 9 is fewer than 12, and 3^3 = 27 is enough: weigh 4 against 4, keep the group of 4 with the fake, then 1 against 1 twice at most.

    This topic is named in a candidate’s interview report: Futureforce SWE intern on-campus interview, 2021, on GeeksforGeeks.

Prep for other employers

All employers
See who is hiring after Salesforce

Engineering internships and entry-level jobs in India, newest first.