Salesforce OA
- Posted
- 20 Jul 2025
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
Hacker Rank test
https://leetcode.com/problems/string-compression/description/
Modified version of https://leetcode.com/problems/delete-and-earn/description/
Questions asked (2)
- 01
String Compression
Data Structures & Algorithms
Open the problemThe 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 strings. For each group of consecutive repeating characters inchars:
If the group's length is 1, append the character tos.
If the group's length is greater than 1, append the character, then append the group's length.
The compressed stringsshould not be returned separately, but instead be stored in the inputcharsarray. 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/ - 02
Modified Delete and Earn
Data Structures & Algorithms
Open the problemI encountered a modified version of the 'Delete and Earn' problem. The base problem is as follows:
You are given an integer arraynums. You want to form a new array by performing some operations onnums. In each operation, you pick anynums[i]and delete it, and you earnnums[i]points. After deletingnums[i], you must also delete all elements equal tonums[i] - 1and all elements equal tonums[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/