Skip to content

Commit e314da0

Browse files
committed
Add solution #1268
1 parent 1af67e8 commit e314da0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@
403403
1249|[Minimum Remove to Make Valid Parentheses](./1249-minimum-remove-to-make-valid-parentheses.js)|Medium|
404404
1252|[Cells with Odd Values in a Matrix](./1252-cells-with-odd-values-in-a-matrix.js)|Easy|
405405
1267|[Count Servers that Communicate](./1267-count-servers-that-communicate.js)|Medium|
406+
1268|[Search Suggestions System](./1268-search-suggestions-system.js)|Medium|
406407
1287|[Element Appearing More Than 25% In Sorted Array](./1287-element-appearing-more-than-25-in-sorted-array.js)|Easy|
407408
1290|[Convert Binary Number in a Linked List to Integer](./1290-convert-binary-number-in-a-linked-list-to-integer.js)|Easy|
408409
1291|[Sequential Digits](./1291-sequential-digits.js)|Medium|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 1268. Search Suggestions System
3+
* https://leetcode.com/problems/search-suggestions-system/
4+
* Difficulty: Medium
5+
*
6+
* You are given an array of strings products and a string searchWord.
7+
*
8+
* Design a system that suggests at most three product names from products after each
9+
* character of searchWord is typed. Suggested products should have common prefix with
10+
* searchWord. If there are more than three products with a common prefix return the
11+
* three lexicographically minimums products.
12+
*
13+
* Return a list of lists of the suggested products after each character of searchWord
14+
* is typed.
15+
*/
16+
17+
/**
18+
* @param {string[]} products
19+
* @param {string} searchWord
20+
* @return {string[][]}
21+
*/
22+
var suggestedProducts = function(products, searchWord) {
23+
products.sort();
24+
const result = new Array(searchWord.length);
25+
for (let i = 0; i < searchWord.length; i++) {
26+
products = products.filter((word) => word[i] === searchWord[i]);
27+
result[i] = products.slice(0, 3);
28+
}
29+
return result;
30+
};

0 commit comments

Comments
 (0)