Salesforce OA

Posted
20 Jul 2025
401 reads

Summary

I had a HackerRank Online Assessment for Salesforce which included two coding problems: String Compression and a modified version of Delete and Earn.

How it went

Questions asked (2)

  1. 01

    String Compression

    Data Structures & Algorithms

    The problem asked to compress an array of characters. You are given an array of characters chars, compress it using the following algorithm:

    Begin with an empty string s. For each group of consecutive repeating characters in chars:

    If the group's length is 1, append the character to s.
    If the group's length is greater than 1, append the character, then append the group's length.
    The compressed string s should not be returned separately, but instead be stored in the input chars array. You must modify the input array in-place and use only O(1) extra space.

    Example 1:
    Input: chars = ["a","a","b","b","c","c","c"]
    Output: Return 6, and the first 6 characters of the input array should be: ["a","2","b","2","c","3"]
    Explanation: "aa" is replaced by "a2". "bb" is replaced by "b2". "ccc" is replaced by "c3".

    Problem link: https://leetcode.com/problems/string-compression/description/

    Open the problem
  2. 02

    Modified Delete and Earn

    Data Structures & Algorithms

    I encountered a modified version of the 'Delete and Earn' problem. The base problem is as follows:

    You are given an integer array nums. You want to form a new array by performing some operations on nums. In each operation, you pick any nums[i] and delete it, and you earn nums[i] points. After deleting nums[i], you must also delete all elements equal to nums[i] - 1 and all elements equal to nums[i] + 1.

    Return the maximum number of points you can earn.

    Problem link for the base problem: https://leetcode.com/problems/delete-and-earn/description/

    Open the problem

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Salesforce recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

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