Problem · Array

Bit Pattern (MTS)

EasySalesforceFULLTIMEOA
See Salesforce hiring insights

Given an array of integers, for each element determine whether that element occurs earlier in the array and whether it occurs later in the array. Create two strings of binary digits. In the first string, each character is a 1 if the value at that index also occurs earlier in the array, or 0 if not. In the second string, each character is a 1 if the value at that index occurs later in the array, or 0 if not. Return an array of two strings where the first string is related to lower indices and the second to higher.

Function Description

Complete the function bitPattern in the editor below.

bitPattern has the following parameter(s):

  1. int num[n]: an array of integers

Returns

string[2]: an array of 2 strings as described

Input Format for Custom Testing

Input from stdin will be processed as follows and passed to the function.

The first line contains an integer n, the size of the array num.
Each of the next n lines contains an integer num[i].

Examples
01 · Example 1
num = [1, 3, 2, 3, 4, 1]
return = ["000101", "110000"]
:)
02 · Example 2
num = [1,2,3,2,1]
return = ["00011", "11000"]

For i = 0, the value 1 does not occur earlier in the array, but it does occur later. The two strings are now ['0', '1'].

For i = 1, the value 2 does not occur earlier in the array, but it does occur later. The two strings are now ['00', '11'].

For i = 2, the value 3 does not occur earlier or later in the array. The two strings are now ['000', '110'].

After similar analyses on the remaining values, the return array is ['00011', '11000'].

Constraints
1 ≤ n ≤ 10^4
0 ≤ num[i] ≤ 10^4
More Salesforce problems
drafts saved locally
public String[] bitPattern(int[] num) {
  // write your code here
}
num[1, 3, 2, 3, 4, 1]
expected["000101", "110000"]
sign in to submit