You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// SearchStrings searches for x in a sorted slice of strings and returns the index
// as specified by Search. The return value is the index to insert x if x is not
// present (it could be len(a)).
// The slice must be sorted in ascending order.
//
func SearchStrings(a []string, x string) int {
It is returning the position of the slice that you can insert your string.
I still have a question. If we see the above code provided by me, I have given the subset of the string available in the slice. The string available at index 2(after sorting) is "Jaipur" but I have provided "Jai" as input to the SearchString. The SearchString returns the index even there is no exact match of the string. So my question is, does the SearchString function check for a subset of the string available in the slice?
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Executed following program:
Please note in above program that I have provided "Jai" to search string. I have not provided "Jaipur" which is availalbe in the string slice.
What did you expect to see?
4
I would expect 4 as output because when the string is not found in slice then the SearchString returns the length of the slice.
What did you see instead?
2
The text was updated successfully, but these errors were encountered: