Challenge: Sparse Search

Given a sorted array of strings interspersed with empty strings, find the index of a given string.

Problem statement

Implement a function that returns the index of the target string in a sorted and sparsed array of strings.

Input

A sparsed, sorted array of strings and the target string whose location needs to be found

Output

Index (location) of the target string

Sample input

array = {"", "educative", "", "", "",  "hello", "", "learning", "world", "", "", ""};

target = "educative"

Sample output

1

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.