As reported: Salesforce LMTS online assessment (HackerRank, 75 minutes, April 2025), problem 1 of 2. Also asked in a 2025 Salesforce MTS online assessment.
Given an integer array nums of length n, return two strings of length n:
- In the first, character
iis'1'ifnums[i]appears at some lower index, else'0'. - In the second, character
iis'1'ifnums[i]appears at some higher index, else'0'.
Example 1
nums = [1,2,1,3,2]
Output: ["00101","11000"]
Example 2
nums = [7]
Output: ["0","0"]
Constraints: 1 ≤ n ≤ 10^5; -10^9 ≤ nums[i] ≤ 10^9.
Code runner format: one line: nums as a JSON array. Implement bitPattern(nums); the harness prints the two strings as a JSON array.