Bit Pattern (MTS)
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.
Complete the function bitPattern in the editor below.
bitPattern has the following parameter(s):
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].
1Example 1
2Example 2
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
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 10^4
0 ≤ num[i] ≤ 10^4