Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Search Character in Strings

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Search Character in Strings. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Amazon search tools may need to locate a character within a collection of product titles. Given an array of strings and a single target character, return the position of the target's first occurrence when scanning strings from left to right and characters from left to right.

Return the position as [string_index, character_index]. If the character does not appear, return [-1, -1]. The search is case-sensitive.

Formal Specification

Implement find_character(strings, target).

  • strings is a list of strings.
  • target is a string containing exactly one character.
  • The return value is a two-element list of integers, [i, j], where i identifies the string and j identifies the character position within that string.
  • Return [-1, -1] when no match exists.

Constraints

  • 1 <= len(strings) <= 10^4
  • Each string contains at most 10^3 characters
  • target contains exactly one character
  • Strings may be empty
  • The search is case-sensitive

Function Signature

def find_character(strings, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output