1p3a Question · Feb 2026

Salesforce Online Assessment Tree and String DP Solutions

Question Details

1. Collect Opportunity Data in a Tree

You are given an undirected tree with n nodes labeled from 0 to n - 1. The tree is defined by n -

Full Details

1. Collect Opportunity Data in a Tree

You are given an undirected tree with n nodes labeled from 0 to n - 1. The tree is defined by n - 1 edges.

Each node represents a branch office. You are also given a binary array opportunityData of size n, where:

  • opportunityData[i] = 1 means branch i contains important data.
  • opportunityData[i] = 0 means it does not.

You may start at any node.

You can traverse edges in both directions.

You must start and end at the same node.

Special Rule

When you are at a node, you can collect data from all nodes within distance ≤ 2 edges from your current location.

Goal

Return the minimum number of edges you must traverse in order to collect all important data.

Example 1


**Input**: n = 11 edges = [[0,1],[0,2],[0,6],[1,3],[1,4],[3,10],[6,7],[7,8],[8,9]] opportunityData = [0,0,1,1,0,0,0,0,0,1,1]

**Output**: 6 

Explanation:

Nodes 2, 3, 9, 10 contain data.

One optimal strategy:

  • Start at node 1
  • From node 1, collect data at 3 and 10 (within distance 2)
  • Travel to node 0 and collect 2
  • Travel toward node 7 to collect 9
  • Return to the starting node

Total edges traversed = 6

Constraints

  • 2 ≤ n ≤ 10^5
  • edges.length == n - 1
  • The input graph is a valid tree
  • opportunityData[i] ∈ {0, 1}

2. Replace '?' to Avoid Adjacent Duplicates

You are given a string s consisting of lowercase English letters ('a''z') and the character '?'.

Each '?' can be replaced with any lowercase English letter.

Return the total number of ways to replace all '?' such that the final string has no two adjacent identical characters.

Since the answer may be large, **return** it modulo 10^9 + 7.

Example 1


**Input**: s = "??"

**Output**: 650 

Explanation:

  • First character: 26 choices
  • Second character: 25 choices (cannot equal previous)
  • Total = 26 × 25 = 650

Constraints

  • 1 ≤ s.length ≤ 10^5
  • s[i] is lowercase English letter or '?'

3. Strings With No k Consecutive Identical Characters

You are given two integers:

  • n: length of string
  • k: maximum allowed consecutive identical characters

A string is invalid if it contains k or more consecutive identical characters.

Return the total number of strings of length n formed using lowercase English letters such that no character appears k or more times consecutively.

Return the answer modulo 10^9 + 7.

Example 1


**Input**: n = 3, k = 2 Output: 16250 

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ k < n
Free preview — 6 questions shown. Unlock all Salesforce questions →

About This Question

This is a reported interview question from a salesforce interview for a swe role during the oa round reported in 2026.

It covers the following topics: Arrays, Binary Tree, Dynamic Programming, Graph, Strings .

About Salesforce Interview Reports

This question was reported by a candidate who interviewed at Salesforce. LeakCode aggregates interview reports from 10+ sources, including 1Point3Acres, Glassdoor, LeetCode Discuss, Blind, Reddit, Indeed, and Nowcoder. Each report is translated where necessary, deduplicated against existing entries, and tagged by company, role, round type, and reporting date.

Use this question as one calibration data point, not a memorization target. Companies typically rotate their question pools every 2-4 months; the exact wording of a 2024 question may differ from what you encounter today. The underlying pattern, difficulty level, and follow-up depth at Salesforce are the higher-signal extractions to take from this report.

For broader preparation context, the Salesforce interview process typically includes a recruiter screen, one or two technical phone screens, and a 4-5 round on-site loop covering coding, system design (at L4+ levels), and behavioral. Reports tagged on LeakCode show the round-by-round distribution and typical difficulty calibration. To browse questions filtered by round type and seniority, use the company hub linked above.

How To Practice This Type of Question

Solve similar problems on LeetCode under timed conditions (25-35 minutes per medium difficulty). The goal is pattern recognition: recognize the underlying technique (sliding window, two-pointer, BFS, memoized recursion, etc.) within 60-90 seconds of reading. Strong candidates verbalize their hypothesis out loud before coding, then iterate based on feedback. Weak candidates dive into implementation immediately, lose time on the wrong approach, and run out of time for follow-ups.

Companies update their question pools every 2-4 months. The exact wording of any given question may have been retired by the time you interview. Focus your prep on the pattern, not the specific problem. The patterns that appear in Salesforce reports consistently are the ones worth investing in; one-off niche problems are not.

During Your Salesforce Round

Apply the standard interview round template: clarify requirements (2-3 minutes), state your approach out loud and confirm direction with the interviewer (3-5 minutes), code with narration (15-25 minutes), test with concrete examples including edge cases (5 minutes), discuss optimization or trade-offs if time permits (5 minutes). This template is universally accepted across FAANG and adjacent companies; deviating from it produces weaker interviewer feedback signal.

The single most predictive failure mode in Salesforce reports tagged "no hire": not asking clarifying questions. Interviewers are explicitly trained to weight this. Strong candidates ask 3-5 clarifying questions even on problems that look obvious; weak candidates dive into code immediately. The clarifying-question check is often the first signal recorded in the interviewer's written notes.