Salesforce OA | SMTS
Summary
I recently completed an Online Assessment for an SMTS position at Salesforce India after cold emailing recruiters. The OA consisted of two specific coding problems, and I cleared it, moving on to F2F rounds.
Full Experience
Hi Folks,
YOE: 6 Currently SSE @ Walmart
Recently gave OA for SMTS position at Salesforce India. Got the OA link after cold emailing a bunch of salesforce recruiters.
#1: Minimum Operations to Zero (Same as LeetCode problem #2571.) You are given an integer n. In one operation, you can either add or subtract any power of 2 (i.e., ±2⁰, ±2¹, ±2², ..., ±2ᵏ) to/from n.
Write a function that returns the minimum number of such operations required to reduce n to 0.
public static int getMinOperations(int n)
Input: A single integer n (1 ≤ n ≤ 10⁹) Output: An integer representing the minimum number of operations to reduce n to 0.
Example: Input: 21 Output: 3
Explanation:
21 → 20 (subtract 1 = 2⁰)
20 → 16 (subtract 4 = 2²)
16 → 0 (subtract 16 = 2⁴)
#2: Integrity Score A data packet is represented as a string of lowercase English letters. The integrity score of the packet is defined as the number of substrings whose character values sum to a number divisible by the length of the substring.
Each character is assigned a value as follows: a,b -> 1 c,d,e -> 2 f,g,h -> 3 i,j,k -> 4 l,m,n -> 5 o,p,q -> 6 r,s,t -> 7 u,v,w -> 8 x,y,z -> 9
Write a function that returns the integrity score of the packet.
public static int integrityScore(String dataPacket)
Input: A string dataPacket consisting of lowercase English letters (1 ≤ length ≤ 10⁵) Output: An integer representing the integrity score.
Example: Input: "cat" Output: 4
Solution:
public static int integrityScore(String dataPacket) {
int n = dataPacket.length();
int[] prefixSum = new int[n + 1];
int count = 0;
// Build prefix sum using custom mapping: 'a' = 1 etc
for (int i = 0; i < n; i++) {
char ch = dataPacket.charAt(i);
prefixSum[i + 1] = prefixSum[i] + getValue(ch);
}
// Check all substrings
for (int start = 0; start < n; start++) {
for (int end = start + 1; end <= n; end++) {
int length = end - start;
int sum = prefixSum[end] - prefixSum[start];
if (sum % length == 0) {
count++;
}
}
}
return count;
}
private static int getValue(char ch) {
return switch (ch) {
case 'a','b' -> 1;
case 'c','d','e' -> 2;
case 'f','g','h' -> 3;
case 'i','j','k' -> 4;
case 'l','m','n' -> 5;
case 'o','p','q' -> 6;
case 'r','s','t' -> 7;
case 'u','v','w' -> 8;
case 'x','y','z' -> 9;
default -> 0;
};
}
Cleared and asked to appear for F2F rounds.
Interview Questions (2)
(Same as LeetCode problem #2571.) You are given an integer n. In one operation, you can either add or subtract any power of 2 (i.e., ±2⁰, ±2¹, ±2², ..., ±2ᵏ) to/from n.
Write a function that returns the minimum number of such operations required to reduce n to 0.
public static int getMinOperations(int n)
Input: A single integer n (1 ≤ n ≤ 10⁹) Output: An integer representing the minimum number of operations to reduce n to 0.
Example: Input: 21 Output: 3
Explanation:
21 → 20 (subtract 1 = 2⁰)
20 → 16 (subtract 4 = 2²)
16 → 0 (subtract 16 = 2⁴)
A data packet is represented as a string of lowercase English letters. The integrity score of the packet is defined as the number of substrings whose character values sum to a number divisible by the length of the substring.
Each character is assigned a value as follows: a,b -> 1 c,d,e -> 2 f,g,h -> 3 i,j,k -> 4 l,m,n -> 5 o,p,q -> 6 r,s,t -> 7 u,v,w -> 8 x,y,z -> 9
Write a function that returns the integrity score of the packet.
public static int integrityScore(String dataPacket)
Input: A string dataPacket consisting of lowercase English letters (1 ≤ length ≤ 10⁵) Output: An integer representing the integrity score.
Example: Input: "cat" Output: 4