Reported July 2026
Salesforcehash table

Generate Seen Binary Strings

Reported by candidates from Salesforce's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Salesforce OA. Under 2s to a working solution.
Founder's read

A hash set or hash map decides this Salesforce OA question, reported in July 2026. Generate Seen Binary Strings looks like string work, but the strings are just output. The real job is tracking what you've seen and what's still coming. If you've got an assessment in the next day or two, expect an array in, two binary strings out, and a linear-time solution as the bar. It's easy once you see it and annoying if you brute force it. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the pattern below should get you there on your own.

The problem

You are given an integer array arr. Return two binary strings of length arr.length:
The first string has 1 at index i if arr[i] appears anywhere after index i; otherwise it has 0.
The second string has 1 at index i if arr[i] appears anywhere before index i; otherwise it has 0.

Function
generateSeenBinaryStrings(arr: int[]) → String[]

Examples
Example 1
arr = [1,2,3,1,2,4,5]
return = ["1100000","0001100"]
The first two values appear again later, so the first string starts with 11. The values at indices 3 and 4 appeared earlier, so the second string has 1 at those positions.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is two passes with hash structures. Going left to right, keep a set of values seen so far. At index i, the second string gets 1 if arr[i] is already in the set, then you add it. For the first string, you need to know if arr[i] appears later. Either run the same scan right to left with a fresh set, or count total occurrences up front and decrement as you go, marking 1 while the remaining count is above zero. The common pitfall is a nested loop that checks every later index. That's O(n^2) and will time out on big inputs. Another slip is adding the value to the set before checking it, which marks every position as seen. Build the output with a list of chars and join once, not repeated string concatenation. If the logic slips under pressure, StealthCoder can hand you the clean two-pass version live.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Generate Seen Binary Strings cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Salesforce's OA.

Salesforce reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Generate Seen Binary Strings FAQ

How hard is Generate Seen Binary Strings really?+

Easy to low-medium. There's no tricky algorithm, just a hash set and careful ordering. Most candidates who fail it write the O(n^2) nested loop or check the set after inserting. If you can explain seen-before versus appears-later, you're fine.

What's the trick to solve it in linear time?+

Use a hash set. Scan left to right for the second string, checking membership before inserting. Scan right to left with a fresh set for the first string. Each pass is O(n), so the whole solution is O(n) time and O(n) space.

Can I do it with one pass instead of two?+

Yes. Build a frequency map first, then walk left to right. Keep a seen set for the second string and decrement the count for the first. If the remaining count of arr[i] is above zero after decrementing, mark 1. It's still two scans total, just structured differently.

What edge cases should I test for the Salesforce OA?+

Test an empty array, a single element, all identical values, and all distinct values. For the example [1,2,3,1,2,4,5], you should get 1100000 and 0001100. Identical values are the best check that your first and second strings stay correct.

How do I prepare for this in 48 hours?+

Practice the seen-set pattern until the check-then-insert order is automatic. Write the right-to-left variant too. Then do a few array and hash map problems that need both directions. This one is about clean ordering, not deep theory.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Salesforce.

OA at Salesforce?
Invisible during screen share
Get it