Salesforce OA
Summary
I had a HackerRank Online Assessment for Salesforce which included two coding problems: String Compression and a modified version of Delete and Earn.
Full Experience
Hacker Rank test
https://leetcode.com/problems/string-compression/description/
Modified version of https://leetcode.com/problems/delete-and-earn/description/
Interview Questions (2)
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/
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/