Reported October 2022
Duolingograph

Visit Desired Attractions Without Reusing a Trail

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

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

Duolingo reported this one in October 2022, and the constraint that matters is trails.length <= 20. That number rules out nothing obvious at first glance, but it tells you the intended solution isn't a clever graph theorem. You're looking for an Euler-style trail question dressed up as a camping walk, where each trail row can be used once and parallel trails count separately. If you have the OA in a day or two, read the constraints before you write anything. A bitmask over trails is on the table. StealthCoder sits invisibly as a safety net if you blank on the state design during the live assessment.

The problem

You are planning a camping walk from Parking Lot to Campsite. Each row of trails is an undirected trail between two attractions. Different rows are different physical trails, so parallel trails between the same two attractions remain independently usable.
Return whether there is a walk that:
starts at Parking Lot;
ends at Campsite;
visits every name in desiredAttractions at least once; and
uses each individual trail row at most once.
An attraction may be visited more than once. Reaching Campsite early does not force the walk to stop; it may leave and return as long as unused trails remain.

Function
canVisitAllAttractions(trails: String[][], desiredAttractions: String[]) → boolean

Examples
Example 1
trails = [["Beaver Dam","Frozen Ocean"],["Beaver Dam","Frozen Ocean"],["Parking Lot","Beaver Dam"],["Parking Lot","Liberty Lake"],["Beaver Dam","Campsite"],["Eel Weir","Campsite"],["Eel Weir","Campsite"]]
desiredAttractions = ["Frozen Ocean"]
return = true
One valid walk is Parking Lot → Beaver Dam → Frozen Ocean → Beaver Dam → Campsite. The two Beaver Dam-Frozen Ocean rows are distinct trails.
Example 2
trails = [["Beaver Dam","Frozen Ocean"],["Beaver Dam","Frozen Ocean"],["Parking Lot","Beaver Dam"],["Parking Lot","Liberty Lake"],["Beaver Dam","Campsite"],["Eel Weir","Campsite"],["Eel Weir","Campsite"]]
desiredAttractions = ["Liberty Lake","Beaver Dam"]
return = false
The only trail incident to Liberty Lake would need to be used both entering and leaving, which is forbidden.
Example 3
trails = [["Beaver Dam","Frozen Ocean"],["Beaver Dam","Frozen Ocean"],["Parking Lot","Beaver Dam"],["Parking Lot","Liberty Lake"],["Beaver Dam","Campsite"],["Eel Weir","Campsite"],["Eel Weir","Campsite"]]
desiredAttractions = ["Eel Weir"]
return = true
A valid walk is Parking Lot → Beaver Dam → Campsite → Eel Weir → Campsite, using the two parallel Eel Weir-Campsite trails once each.

Constraints
1 <= trails.length <= 20.
Every trail row contains exactly two non-empty attraction names.
Parallel trail rows are allowed and have separate identities.
0 <= desiredAttractions.length <= 15; duplicates in this list do not require multiple visits.
Every desired attraction appears in at least one trail row.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The brute force is a DFS that tries every ordering of trail use, which is up to 20! paths in the worst case. Cut it down with state: (current node, bitmask of used trails). That's at most nodes x 2^20 states, which is fine. Run DFS or BFS from Parking Lot, flip a bit when you cross a trail, and track visited desired attractions inside the walk. Accept when you stand on Campsite and every desired node has been seen. The pitfall is stopping at Campsite early. The walk can leave and come back, so don't return on first arrival. Another trap is merging parallel trails, which breaks Example 3. Index each row separately. Desired attractions can be a second mask of up to 15 bits, or you can recompute it from the used edges. If the memoization setup slips under time pressure, StealthCoder is the hedge that hands you the working structure.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Visit Desired Attractions Without Reusing a Trail 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Duolingo reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Visit Desired Attractions Without Reusing a Trail FAQ

How hard is this Duolingo OA problem really?+

Medium to hard. The idea is simple, search over walks, but you need to see that 20 trails allows a bitmask. Candidates who try pure DFS without memoization usually time out on dense inputs. Parallel trails and revisiting nodes add edge cases.

What's the trick to avoid brute force?+

Memoize on (current node, mask of used trail indices). With 20 trails that's about a million masks per node. Each state tries every unused trail incident to the current node, so it stays tractable.

Do parallel trails really matter?+

Yes. Each row is its own trail with its own bit. Example 1 needs both Beaver Dam to Frozen Ocean rows, one to go and one to return. If you dedupe edges into a set, you'll get that wrong.

Can the walk pass through Campsite and keep going?+

Yes. Example 3 visits Campsite, goes to Eel Weir, and comes back. Only check the end condition when you finish, meaning you stand on Campsite with all desired attractions seen. Don't terminate on first arrival.

How do I prep for this in 48 hours?+

Practice bitmask DP on small graphs and DFS with visited-edge tracking. Write one solution that tracks used edges by index and memoizes on (node, mask). Then test the three examples by hand, especially the Liberty Lake dead-end case.

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

OA at Duolingo?
Invisible during screen share
Get it