A shop records its daily sales in a string called salesLog. Each letter identifies a product type, and each occurrence represents one unit sold. Sales appear in the order they happened.
Find the first sale of a product that was sold exactly once during the entire day.
int firstSingleSaleIndex(String salesLog)
salesLog: the day's sales in chronological order.-1 if none exists.1 ≤ salesLog.length() ≤ 100,000salesLog contains only lowercase English letters.firstSingleSaleIndex(salesLog = "tggv")
Output: 0
Products t and v were each sold once. The sale of t appears first, at index 0.
firstSingleSaleIndex(salesLog = "ppqrqsr")
Output: 5
Only product s was sold once. Its sale is at index 5.
firstSingleSaleIndex(salesLog = "xyyxy")
Output: -1
Both product types were sold more than once.