Salesforce interview experience Real time questions & tips from candidates to crack your interview

Member of Technical Staff

Salesforce
upvote
share-icon
4 rounds | 9 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 4 Months
Topics: Data Structures, Algorithms, System Design, Aptitude, OOPS
Tip
Tip

Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.

Application process
Where: Campus
Eligibility: Above 7 CGPA
Resume Tip
Resume tip

Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.

Interview rounds

01
Round
Medium
Online Coding Test
Duration90 minutes
Interview date27 Jul 2021
Coding problem2

This was an online coding round where we had 2 questions to solve under 90 minutes . Both the questions were of easy
to medium level of difficulty .

Moderate
20m average time
80% success
0/80
Asked in companies
HCL TechnologiesAmazonOracle

You are given an ‘M*N’ Matrix, You need to print all possible paths from its top left corner to the bottom right corner if given that you can either move right i.e from (i,j) to (i,j+1) or down i.e from (i, j) to (i+1, j).

For Example :
1 2 3
4 5 6

For the above 2*3 matrix , possible paths are (1 2 3 6) , (1 2 5 6) , (1 4 5 6).
Note :
You can return the paths in any order.
Problem approach

Approach : 

Let ‘allAllPaths(n, m, edges, src, des)’ be the function that returns a 2D array that contains all the possible paths.

1) Take the following variables: 2D array ‘Graph’, to store graphs and ‘Visited’ array to mark each node whether it is visited or not.

2) Clear graph, initialize the visited array to false.

3) Run a loop from 0 to 'm' :
Add the undirected edge between edges[i] [0] and edges[i][1].

4) Take an 2D array 'allPaths' to store the answer.

5) Take an array 'currPath' to store the current path.

6) Push ‘src’ in ‘currPath’ and mark visited[src] equal to true.

7) Make a dfs(n, allPaths, currPath, src, des, graph, visited) and call the dfs function.

8) Return ‘allPaths’. 


TC : O(N ^ N), where N = number of vertices
SC : O(N ^ N)

Try solving now

2. Spiral Matrix

Easy
15m average time
80% success
0/40
Asked in companies
JP MorganSalesforceApple

You are given a 2-D array 'MATRIX' of dimensions N x M, of integers. You need to return the spiral path of the matrix.

Example Of Spiral Path:

Spiral path of a matrix

Problem approach

Approach : 

1) Run loop until all the squares of loops are printed.

2) In each outer loop traversal push the elements of a square in a clockwise manner.

3) Push the top row, i.e. Push the elements of a kth row and increase k..

4) Push the right column, i.e. Push the last column and decrease the count of columns.

5) Push the bottom row, and decrease the count of rows.

6) Push the left column, and increase the count of the starting column index.


TC : O(N*M), where N = number of rows and M = number of columns
SC : O(1)

Try solving now
02
Round
Medium
Video Call
Duration45 Minutes
Interview date27 Jul 2021
Coding problem2

This round had 2 coding questions , the first one was related to Dynamic Programming and the second one was of Binary Trees. I first explained the approach with proper complexity analysis and then moved on to code both the solutions.

1. Best Time To Buy and Sell Stock

Hard
20m average time
80% success
0/120
Asked in companies
AdobeRazorpayOYO

You have been given an array 'PRICES' consisting of 'N' integers where PRICES[i] denotes the price of a given stock on the i-th day. You are also given an integer 'K' denoting the number of possible transactions you can make.

Your task is to find the maximum profit in at most K transactions. A valid transaction involves buying a stock and then selling it.

Note
You can’t engage in multiple transactions simultaneously, i.e. you must sell the stock before rebuying it.
For Example
Input: N = 6 , PRICES = [3, 2, 6, 5, 0, 3] and K = 2.
Output: 7

Explanation : The optimal way to get maximum profit is to buy the stock on day 2(price = 2) and sell it on day 3(price = 6) and rebuy it on day 5(price = 0) and sell it on day 6(price = 3). The maximum profit will be (6 - 2) + (3 - 0) = 7.
Problem approach

Approach : 

1) We initialize two 2-D matrices, buy[K+1][N+1] and sell[K+1][N+1]. 

2) Here, buy[i][j] will denote the maximum profit we can get in at most ‘i’ transactions from the array starting from index 0 and ending at index j -1 and the final state is buying the stock. 

3) sell[i][j] will denote the maximum profit we can get in at most ‘i’ transactions from the array starting from index 0 and ending at index j -1 and the final state is not holding the stock i.e. selling the stock.

4) We iterate the matrix buy and sell column-wise and update the values.

4.1) buy[j][i] = max(buy[j][i-1], sell[j-1][i-1] - PRICES[i-1]). Here buy[j][j-1] denotes holding the stock and sell[j -1][i - 1] - PRICES[i -1] denotes buying the stock on i-th day.

4.2) sell[j][i] = max(sell[j][i-1], buy[j][i-1]+PRICES[i-1]). Here sell[j][i-1] denotes not holding the stock and buy[i][j - 1] + PRICES[i -1] denotes selling the stock on i-th day.

5) Finally return sell[K][N].


TC : O(N*K), where N = size of the array and K = max number of transactions allowed
SC : O(N*K)

Try solving now

2. Diagonal Traversal of a binary tree.

Easy
10m average time
90% success
0/40
Asked in companies
Paytm (One97 Communications Limited)AmazonSalesforce

You have been given a binary tree of integers. You are supposed to find the diagonal traversal(refer to Example) of the given binary tree.

Example:

Consider lines at an angle of 135 degrees(with respect to standard X- axis)  in between nodes. Then, all nodes between two consecutive lines belong to the same diagonal

alt text

The diagonal traversal for the above tree is: 

0 2 6 1 5 3 4 7 
Problem approach

Approach : 

1) Assign the diagonal number of the root as 0.

2) Do a preorder traversal of the binary tree and for each node keep track of the diagonal number.
2.1) Insert the value of the current node in the Map with the key as the diagonal number of the current node.
2.2) Now increase the diagonal number by 1 for the left child of the node and recursively traverse the left subtree.
2.3) Recursively traverse the right subtree and keep the diagonal number the same as the current node.

3) Initialize an empty array to store the diagonal traversal, let’s say 'traversal'

4) Iterate through the Map and add all the values of the Map to 'traversal'.

5) Finally, Return 'traversal'.


TC : O(N * log(N)) , where N = number of nodes in the binary tree
SC : O(N)

Try solving now
03
Round
Medium
Video Call
Duration60 Minutes
Interview date27 Jul 2021
Coding problem4

The interviewer asked 2 coding problems in this round followed by some questions from Operating System.

1. Optimal Strategy for a Game

Easy
15m average time
85% success
0/40
Asked in companies
GoogleIBMJP Morgan

You and your friend Ninjax are playing a game of coins. Ninjax place the 'N' number of coins in a straight line.

The rule of the game is as follows:

1. Each coin has a value associated with it.

2. It’s a two-player game played against an opponent with alternating turns. 

3. At each turn, the player picks either the first or the last coin from the line and permanently removes it.

4. The value associated with the coin picked by the player adds up to the total amount the player wins. 

Ninjax is a good friend of yours and asks you to start first.

Your task is to find the maximum amount you can definitely win at the end of this game.

Note:

'N' is always even number.

Ninjax is as smart as you, so he will play so as to maximize the amount he wins.
Example 1:
Let the values associated with four coins be: [9, 5, 21, 7] 

Let’s say that initially, you pick 9 and Ninjax picks 7.
Then, you pick 21 and Ninjax picks 5. 
So, you win a total amount of (9+21), i.e. 30.

In case you would have picked up 7 initially and Ninjax would have picked 21 (as he plays optimally). 
Then, you would pick 9 and Ninjax would choose 5. So, you win a total amount of (7+9), i.e. 16, which is not the maximum you can obtain.

Thus, the maximum amount you can win is 30.
Example 2:
Let the values associated with four coins be: [20, 50, 5, 10] 

Let’s say that initially, you pick 10 and Ninjax picks 20.
Then, you pick 50 and Ninjax picks 5. 
So, you win a total amount of (10+50), i.e. 60.

In case you would have picked up 20 initially and Ninjax would have picked 50 (as he plays optimally). 
Then, you would pick 10 and Ninjax would choose 5. So, you win a total amount of (20+10), i.e. 30, which is not the maximum you can obtain.

Thus, the maximum amount you can win is 60.
Problem approach

Approach :

1) The idea is to create a 2D table of size N*N.

2) Each entry in the table stores the solution to a subproblem i.e. ‘TABLE’['I']['J'] represents the maximum amount you
can win for the subarray ‘COINS’['I', 'J'] given that you start first.

3) The algorithm for filling the table is as follows :
Loop 1: For ‘LEN’ = 1 to ‘N’:
Loop 2: For ‘I’ = 0 to ('N' - ‘LEN’):
→Let 'J' = 'I' + ‘LEN’ - 1
→If ('I'+1) < N && ('J'-1) >= 0 then, A = ‘DP’['I'+1]['J'-1], otherwise A = 0.
→If (i+2) < N then, B = ‘DP’['I'+2]['J'], otherwise B = 0.
→ If ('J'-2) >= 0 then, C = ‘DP’['I']['J'-2], otherwise C = 0.
→ Update ‘DP’['I']['J'] = max(‘COINS’['I'] + min(A, B), coins['J'] + min(A, C)).
End Loop 2.
End Loop 1.

4) ‘DP’[0]['N'-1] stores the final answer.


TC : O(N^2) , where N = number of coins
SC : O(N^2)

Try solving now

2. Count Ways To Reach The N-th Stairs

Moderate
30m average time
80% success
0/80
Asked in companies
InfosysTata Consultancy Services (TCS)PhonePe

You have been given a number of stairs. Initially, you are at the 0th stair, and you need to reach the Nth stair.


Each time, you can climb either one step or two steps.


You are supposed to return the number of distinct ways you can climb from the 0th step to the Nth step.

Note:

Note: Since the number of ways can be very large, return the answer modulo 1000000007.
Example :
N=3

Example

We can climb one step at a time i.e. {(0, 1) ,(1, 2),(2,3)} or we can climb the first two-step and then one step i.e. {(0,2),(1, 3)} or we can climb first one step and then two step i.e. {(0,1), (1,3)}.
Problem approach

Approach (Using DP) :

1) We reach “currStep” step in taking one step or two steps:
1.1) We can take the one-step from (currStep-1)th step or,
1.2) We can take the two steps from (currStep-2)th step.

2) So the total number of ways to reach “currStep” will be the sum of the total number of ways to reach at (currStep-
1)th and the total number of ways to reach (currStep-2)th step.

3) Let dp[currStep] define the total number of ways to reach “currStep” from the 0th. So,
dp[ currStep ] = dp[ currStep-1 ] + dp[ currStep-2 ]

4) The base case will be, If we have 0 stairs to climb then the number of distinct ways to climb will be one
(we are already at Nth stair that’s the way) and if we have only one stair to climb then the number of
distinct ways to climb will be one, i.e. one step from the beginning.


TC : O(N), Where ‘N’ is the number of stairs.
SC : O(N)

Try solving now

3. OS Question

What are the different types of semaphores ?

Problem approach

There are two main types of semaphores i.e. counting semaphores and binary semaphores.

1) Counting Semaphores :
These are integer value semaphores and have an unrestricted value domain. These semaphores are used to
coordinate the resource access, where the semaphore count is the number of available resources. If the resources
are added, semaphore count automatically incremented and if the resources are removed, the count is decremented.


2) Binary Semaphores :
The binary semaphores are like counting semaphores but their value is restricted to 0 and 1. The wait operation only
works when the semaphore is 1 and the signal operation succeeds when semaphore is 0. It is sometimes easier to
implement binary semaphores than counting semaphores.

4. OS Question

What is a deadlock in OS? What are the necessary conditions for a deadlock?

Problem approach

Deadlock is generally a situation where a set of processes are blocked as each process is holding resources and
waits to acquire resources held by another process. In this situation, two or more processes simply try to execute
simultaneously and wait for each to finish their execution because they are dependent on each other. We can see a
hand problem in our system whenever a deadlock occurs in a program. It is one of the common problems you can
see in multiprocessing.

Necessary Conditions for Deadlock

There are basically four necessary conditions for deadlock as given below:

1) Mutual Exclusion
2) Hold and Wait
3) No Pre-emption
4) Circular Wait or Resource Wait

04
Round
Easy
HR Round
Duration30 Minutes
Interview date27 Jul 2021
Coding problem1

This was a typical HR round with some standard Behavioral questions.

1. Basic HR Question

Tell me something not there in your resume.

Problem approach

If you get this question, it's an opportunity to choose the most compelling information to share that is not obvious from
your resume.

Example :

Strength -> I believe that my greatest strength is the ability to solve problems quickly and efficiently, which makes me
unique from others.

Abillity to Handle Pressure -> I enjoy working under pressure because I believe it helps me grow and become more
efficient .


Tip : Emphasize why you were inspired to apply for the job. You can also explain that you are willing to invest a great
deal of energy if hired.

These are generally very open ended questions and are asked to test how quick wit a candidate is. So there is
nothing to worry about if you have a good command over your communication skills and you are able to propagate
your thoughts well to the interviewer

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

Which keyword is used for inheritance?

Choose another skill to practice
Similar interview experiences
company logo
Member of Technical Staff
4 rounds | 6 problems
Interviewed by Salesforce
1212 views
0 comments
0 upvotes
company logo
SDE - 1
4 rounds | 7 problems
Interviewed by Salesforce
3046 views
0 comments
0 upvotes
company logo
SDE - 1
2 rounds | 4 problems
Interviewed by Salesforce
965 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 9 problems
Interviewed by Salesforce
2164 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
Member of Technical Staff
4 rounds | 13 problems
Interviewed by Oracle
5011 views
0 comments
0 upvotes
company logo
Member of Technical Staff
3 rounds | 10 problems
Interviewed by Adobe
893 views
0 comments
0 upvotes
company logo
Member of Technical Staff
2 rounds | 5 problems
Interviewed by Oracle
1382 views
0 comments
0 upvotes