FastPrepBit Pattern (MTS)
Problems/Bit Pattern (MTS)

Bit Pattern (MTS)

Salesforce logoSalesforce● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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):

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

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

Function

bitPattern(num: int[]) → String[]

Examples

Example 1

num = [1, 3, 2, 3, 4, 1]return = ["000101", "110000"]

:)

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 interview questions

  • Count Subarrays With Product Equal to KOA · Seen Dec 2026
  • Get Minimum TimeOA · Seen Nov 2026
  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
  • Get Message StatusOA · Seen Nov 2026

Similar questions at other companies

  • Build the Task HierarchyPendo · OA
  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Count Valid Square PairsAuxoAI · OA
  • Two SumAmazon · OA · PHONE SCREEN
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Customer Signer ScreeningState Farm · OA
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public String[] bitPattern(int[] num) {
      // write your code here
    }

}
Checking account…