FastPrepFastPrep
Problem Brief

Bit Pattern (MTS)

FULLTIMEOA

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].

1Example 1

Input
num = [1, 3, 2, 3, 4, 1]
Output
["000101", "110000"]
Explanation
:)

2Example 2

Input
num = [1,2,3,2,1]
Output
["00011", "11000"]
Explanation

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
public String[] bitPattern(int[] num) {
  // write your code here
}
Input

num

[1, 3, 2, 3, 4, 1]

Output

["000101", "110000"]

Sign in to submit your solution.