FastPrepFind the First Matching Ordered Entry

Find the First Matching Ordered Entry

Figma logoFigma● EasyINTERNOA
Learn

Problem statement

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.

More Figma problems

See Figma hiring insights
public int findOrderedEntry(String[] entries, String target) {
    // Write your code here.
}
entries["ant","bee","cat","dog"]
target"cat"
expected2
Checking account…