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].
num = [1, 3, 2, 3, 4, 1] return = ["000101", "110000"]
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'].
1 ≤ n ≤ 10^4
0 ≤ num[i] ≤ 10^4- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
- Replace '?' to Avoid Adjacent DuplicatesOA · Seen Feb 2026
- Strings With No k Consecutive Identical CharactersOA · Seen Feb 2026
- Spam ClassificationSeen Jun 2025
public String[] bitPattern(int[] num) {
// write your code here
}