[Salesforce] OA 2025 start – 8 May (generic)

Question 1: Detect Earlier and Later Occurrences

Description

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 also occurs later in the array, or 0 if not.

Return an array of two strings where the first string corresponds to earlier indices (lower) and the second to later indices (higher).

Input Example

num = [1, 2, 3, 2, 1]

Output Example

['00011', '11000']

Explanation

Index-by-index analysis:

  • Index 0, value 1:
    Earlier → [], Later → [2, 3, 2, 1] → appears later → string1: 0, string2: 1
  • Index 1, value 2:
    Earlier → [1], Later → [3, 2, 1] → appears later → string1: 0, string2: 1
  • Index 2, value 3:
    Earlier → [1, 2], Later → [2, 1] → does not appear again → string1: 0, string2: 0
  • Index 3, value 2:
    Earlier → [1, 2, 3], Later → [1] → appears earlier → string1: 1, string2: 0
  • Index 4, value 1:
    Earlier → [1, 2, 3, 2], Later → [] → appears earlier → string1: 1, string2: 0

Final binary strings:

string1 = "00011"
string2 = "11000"

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *