Find the First Matching Ordered Entry
Reported by candidates from Figma's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Figma reported this one in September 2022, and it looks too easy, which is the trap. You're handed a sorted array of up to 200000 lowercase strings and asked for the first index of a target. A linear scan passes the examples and then dies on scale. This is binary search on strings, specifically the lower-bound flavor, because duplicates are allowed and you must return the leftmost match. If you blank on the boundary logic during the assessment, StealthCoder runs invisibly as a safety net and gives you a working version in real time.
The problem
Given a lexicographically nondecreasing array of lowercase ASCII strings entries and a lowercase ASCII string target, return the index of the first entry equal to target. If target does not appear, return -1. Duplicate entries are allowed. Function findOrderedEntry(entries: String[], target: String) → int Examples Example 1 entries = ["ant","bee","cat","dog"] target = "cat" return = 2 cat appears at index 2. Example 2 entries = ["a","b","b","b","c"] target = "b" return = 1 The first of the three matching entries is at index 1. Example 3 entries = [] target = "z" return = -1 An empty collection contains no matching entry. Constraints 0 <= entries.length <= 200000. Each entry and target contains between 1 and 100 lowercase ASCII letters. entries is sorted in lexicographically nondecreasing order.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The input size is the hint. With 200000 entries, each up to 100 characters, brute force costs about 20 million character comparisons in the worst case. It might scrape by, but the sorted guarantee is screaming for binary search. The trick is the lower bound. Set lo = 0 and hi = n. While lo < hi, compute mid. If entries[mid] < target, move lo to mid + 1. Otherwise set hi = mid. When the loop ends, check that lo < n and entries[lo] equals target, then return lo, else -1. The common pitfall is returning as soon as you find a match, which gives you any duplicate, not the first. Another is forgetting the empty array. Language string comparison is already lexicographic, so don't hand-roll it. Total cost is O(m log n), with m up to 100. StealthCoder is the hedge if the off-by-one bites you live.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Find the First Matching Ordered Entry 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Figma's OA.
Figma reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find the First Matching Ordered Entry FAQ
What's the trick in this Figma OA problem?+
Use lower-bound binary search instead of a plain one. When entries[mid] is less than target, go right. Otherwise shrink hi to mid, even on equality. That keeps pushing left through duplicates until you land on the first match. Then verify equality before returning the index.
Why not just scan linearly?+
With up to 200000 entries it may technically pass, but the sorted input is a signal the grader expects O(log n) comparisons. A linear scan ignores the guarantee and can time out on worst-case tests. Binary search is also only a few lines, so there's no reason to skip it.
How do I handle duplicates correctly?+
Don't return when you hit a match. Keep searching the left half by setting hi = mid when entries[mid] >= target. After the loop, lo points to the first position not less than target. Check that it's in bounds and equals target. Example 2 should give index 1.
Do I need to write custom string comparison?+
No. Most languages compare strings lexicographically with built-in operators or compareTo. Entries are lowercase ASCII, so the default ordering matches the problem. Just be careful in languages where comparison returns an integer, and check its sign properly.
How should I prep for this in 48 hours?+
Write lower-bound binary search from memory three times, on ints first, then strings. Test the empty array, a single element, all duplicates, target smaller than everything, and target larger than everything. Those edge cases are where this problem actually fails candidates.