Salesforce SMTS HackerRank OA 2026 - Both Solved

salesforce logo
salesforce
· Senior Member of Technical Staff (SMTS)· 6y exp
July 23, 2026 · 0 reads

Summary

I completed the Salesforce SMTS online assessment, solving both coding questions within the time limit.

Full Experience

Just completed the Salesforce Senior Member of Technical Staff (SMTS) Online Assessment on HackerRank with 6 years of experience. It had 2 coding questions with a combined time limit. Managed to solve both within the allotted time. Sharing the problems and my approach for others targeting senior roles at Salesforce.

  • Role: Senior Member of Technical Staff (SMTS)
  • Experience: 6 years
  • Platform: HackerRank
  • Language Used: Java

Question 1 - Minimum Segments with No Repeated Characters

Problem Statement: Given a string s, find the minimum number of non-empty disjoint segments the string can be partitioned into, such that each segment contains no repeated characters, after performing the following operation exactly once: Choose any one lowercase English character and remove all its occurrences from the string.

Constraints:

  • 1 ≤ |s| ≤ 2 * 10^5
  • String s consists only of lowercase English letters.

Examples:

Input: s = "abcccde"
Output: 1
Explanation: Remove 'c' → "abde" → 1 segment (no repeats)

Input: s = "abdaa"
Output: 1
Explanation: Remove 'a' → "bd" → 1 segment

Approach: Try removing each of the 26 characters one at a time. For each candidate removal, greedily scan the string and count the minimum number of no‑repeat segments using a bitmask to track characters in the current segment. Take the minimum across all 26 tries.

Time complexity: O(26 * n)
Space complexity: O(1)

Solution:

public static int getNoRepeatSegments(String s) {
    int best = Integer.MAX_VALUE;
    for (char rm = 'a'; rm <= 'z'; rm++) {
        int segments = 0, mask = 0;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == rm) continue;
            int bit = 1 << (ch - 'a');
            if ((mask & bit) != 0) {
                segments++;
                mask = bit;
            } else {
                if (mask == 0) segments++;
                mask |= bit;
            }
        }
        best = Math.min(best, segments);
    }
    return best;
}

Question 2 - Minimum Operations to Reduce N to Zero

Problem Statement: Given a positive integer n, you can either add or subtract 2^i (where i ≥ 0) in a single operation. Determine the minimum number of operations required to reduce n to 0.

Constraints:

  • 1 ≤ n < 2^60

Examples:

Input: n = 5
Output: 2
Explanation:
5 - 2^0 = 4
4 - 2^2 = 0
→ 2 operations

Input: n = 21
Output: 3

Approach: This reduces to finding the Non‑Adjacent Form (NAF) representation of n – the minimum weight signed binary representation. Greedily process two low bits at a time:

  • If n ≡ 3 (mod 4) (trailing 11 in binary) – add 1 to collapse the run via carry
  • If n ≡ 1 (mod 4) (trailing 01) – subtract 1
Then right‑shift. Each nonzero step costs exactly one operation. NAF is proven to be the optimal‑weight signed binary representation.

Time complexity: O(log n)
Space complexity: O(1)

Solution:

public static int getMinOperations(long n) {
    int ops = 0;
    while (n > 0) {
        if ((n & 3) == 3) {
            ops++;
            n++;
        } else if ((n & 1) == 1) {
            ops++;
            n--;
        }
        n >>= 1;
    }
    return ops;
}

Key Observations for Senior-Level Candidates:

  • Q1: Brute forcing all 26 characters is intentional – the constraint |s| ≤ 2*10^5 makes O(26n) well within limits. The bitmask eliminates array allocation overhead in the inner loop.
  • Q2: The naive popcount of binary representation is wrong – the add operation makes this a signed binary problem. Recognizing NAF is the crux. Missing that long type over int for n < 2^60 is an easy trap.
  • Both solutions are O(1) space which matters at SMTS level – interviewers expect awareness of memory beyond just time complexity.

Good luck to everyone else in the Salesforce SMTS pipeline! Drop questions in the comments.

Interview Questions (2)

1.

Minimum Segments with No Repeated Characters

Data Structures & Algorithms

Problem: Given a string s, find the minimum number of non‑empty disjoint segments the string can be partitioned into, such that each segment contains no repeated characters, after performing exactly one operation: choose any one lowercase English character and remove all its occurrences from the string.

Constraints:

  • 1 ≤ |s| ≤ 2 * 10^5
  • s consists only of lowercase English letters.

Examples: Input: s = "abcccde" Output: 1 Explanation: Remove 'c' → "abde" → 1 segment (no repeats)

Input: s = "abdaa" Output: 1 Explanation: Remove 'a' → "bd" → 1 segment

2.

Minimum Operations to Reduce N to Zero

Data Structures & Algorithms

Problem: Given a positive integer n, you can either add or subtract 2^i (where i ≥ 0) in a single operation. Determine the minimum number of operations required to reduce n to 0.

Constraints:

  • 1 ≤ n < 2^60

Examples: Input: n = 5 Output: 2 Explanation: 5 - 2^0 = 4, 4 - 2^2 = 0 → 2 operations

Input: n = 21 Output: 3

📣 Found this helpful? Please share it with friends who are preparing for interviews!

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!