question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
online-election | Accepted C# Bin Search Solution | accepted-c-bin-search-solution-by-maxpus-xe61 | \n public class TopVotedCandidate\n {\n private readonly (int time, int winner)[] _data;\n\n public TopVotedCandidate(int[] persons, int[] t | maxpushkarev | NORMAL | 2020-01-28T06:39:34.348060+00:00 | 2020-01-28T06:39:34.348094+00:00 | 127 | false | ```\n public class TopVotedCandidate\n {\n private readonly (int time, int winner)[] _data;\n\n public TopVotedCandidate(int[] persons, int[] times)\n {\n int currentWinner = -1;\n int maxScore = 0;\n\n IDictionary<int, int> person2Score = new Dictionary<int, ... | 1 | 0 | ['Binary Search'] | 0 |
online-election | Easy to understand C++ Solution | easy-to-understand-c-solution-by-pooja04-vt0b | Runtime: 324 ms, faster than 91.31% of C++ online submissions for Online Election.\nMemory Usage: 74.8 MB, less than 100.00% of C++ online submissions for Onlin | pooja0406 | NORMAL | 2019-10-10T14:27:54.870854+00:00 | 2019-10-10T14:27:54.870899+00:00 | 152 | false | Runtime: 324 ms, faster than 91.31% of C++ online submissions for Online Election.\nMemory Usage: 74.8 MB, less than 100.00% of C++ online submissions for Online Election.\n\n```\nclass TopVotedCandidate {\npublic:\n vector<int> time;\n vector<int> leading;\n TopVotedCandidate(vector<int>& persons, vector<int>... | 1 | 0 | ['Binary Search'] | 0 |
online-election | C# Binary Search Beating 95% | c-binary-search-beating-95-by-dpjha84-9uet | \npublic class TopVotedCandidate {\n Dictionary<int, int> map;\n int[] temp, times;\n public TopVotedCandidate(int[] persons, int[] times) \n {\n | dpjha84 | NORMAL | 2019-08-29T14:30:29.579874+00:00 | 2019-08-29T14:30:29.579912+00:00 | 90 | false | ```\npublic class TopVotedCandidate {\n Dictionary<int, int> map;\n int[] temp, times;\n public TopVotedCandidate(int[] persons, int[] times) \n {\n this.times = times;\n map = new Dictionary<int, int>();\n temp = new int[persons.Length];\n int max = 0;\n for(int i = 0; i ... | 1 | 0 | [] | 0 |
online-election | Java tree map solution | java-tree-map-solution-by-lpx1233-5cw2 | java\nimport java.util.*;\nclass TopVotedCandidate {\n\n private TreeMap<Integer, Integer> res;\n\n public TopVotedCandidate(int[] persons, int[] times) {\n | lpx1233 | NORMAL | 2019-08-23T15:33:13.163760+00:00 | 2019-08-23T15:33:13.163807+00:00 | 88 | false | ```java\nimport java.util.*;\nclass TopVotedCandidate {\n\n private TreeMap<Integer, Integer> res;\n\n public TopVotedCandidate(int[] persons, int[] times) {\n res = new TreeMap<>();\n int[] cnt = new int[persons.length];\n int max = -1;\n for (int i = 0; i < times.length; i++) {\n int t = times[i];\... | 1 | 0 | [] | 0 |
online-election | clean Java code using binary search beats 96% | clean-java-code-using-binary-search-beat-yr3u | \nclass TopVotedCandidate {\n \n int[] leaders;\n int[] times;\n public TopVotedCandidate(int[] persons, int[] times) {\n this.times = times; | swimmingdog | NORMAL | 2019-02-27T05:24:52.374069+00:00 | 2019-02-27T05:24:52.374116+00:00 | 119 | false | ```\nclass TopVotedCandidate {\n \n int[] leaders;\n int[] times;\n public TopVotedCandidate(int[] persons, int[] times) {\n this.times = times;\n int N = persons.length;\n Map<Integer, Integer> map = new HashMap<>();\n leaders = new int[N];\n for (int i = 0; i < N; i++) {... | 1 | 0 | [] | 0 |
online-election | Java TreeMap solution. O(nlogn) + O(logn). | java-treemap-solution-onlogn-ologn-by-ji-au22 | I used a hashmap to keep track of each candidate and its vote count. And I used a treemap to keep track of the leading candidate at times[i]. \n\nComplexity an | jingjing_334 | NORMAL | 2018-09-27T06:10:04.630861+00:00 | 2018-10-24T00:51:43.242025+00:00 | 337 | false | I used a hashmap to keep track of each candidate and its vote count. And I used a treemap to keep track of the leading candidate at times[i]. \n\nComplexity analysis: \n1. TopVotedCandidate() should be O(nlog(n)).-thanks to @bakhodir10 for pointing this out. \n2. q() is O(log(n)) to locate floorkey, and O(1) to return... | 1 | 0 | [] | 2 |
online-election | [Java] Simple TreeMap solution with good comments | java-simple-treemap-solution-with-good-c-pc9p | \nclass TopVotedCandidate {\n \n /**\n * TreeMap contains the times when the leader of the race changed.\n * Key: Time when the race changed lea | jmcelvenny | NORMAL | 2018-09-24T04:37:50.608965+00:00 | 2018-09-24T12:37:35.701902+00:00 | 175 | false | ```\nclass TopVotedCandidate {\n \n /**\n * TreeMap contains the times when the leader of the race changed.\n * Key: Time when the race changed leaders.\n * Value: The new leading candidate.\n */ \n private TreeMap<Integer, Integer> winners;\n\n public TopVotedCandidate(int[] persons, int[... | 1 | 0 | [] | 0 |
online-election | Java TreeMap solution with chinese explanation | java-treemap-solution-with-chinese-expla-0zvs | https://www.jianshu.com/p/9dfa149953c2\n\nTreeMap<Integer,Integer> t = new TreeMap<>();\n public TopVotedCandidate(int[] persons, int[] times) {\n int | happyleetcode | NORMAL | 2018-09-23T03:24:48.410009+00:00 | 2018-09-23T06:31:19.401259+00:00 | 123 | false | https://www.jianshu.com/p/9dfa149953c2\n```\nTreeMap<Integer,Integer> t = new TreeMap<>();\n public TopVotedCandidate(int[] persons, int[] times) {\n int l = times.length;\n Map<Integer,int[]> m = new HashMap<>();\n TreeSet<int[]> t2 = new TreeSet<>((a,b)->{\n if(a[0]==b[0]) return b[... | 1 | 0 | [] | 0 |
online-election | Java TreeMap with Cache | java-treemap-with-cache-by-wangzi6147-oyxx | \nclass TopVotedCandidate {\n \n private TreeMap<Integer, Integer> map = new TreeMap<>();\n private Map<Integer, Integer> cache = new HashMap<>();\n\n | wangzi6147 | NORMAL | 2018-09-23T03:18:21.113474+00:00 | 2018-09-25T09:32:19.031235+00:00 | 188 | false | ```\nclass TopVotedCandidate {\n \n private TreeMap<Integer, Integer> map = new TreeMap<>();\n private Map<Integer, Integer> cache = new HashMap<>();\n\n public TopVotedCandidate(int[] persons, int[] times) {\n Map<Integer, Integer> votes = new HashMap<>();\n int maxC = persons[0];\n vo... | 1 | 0 | [] | 1 |
online-election | using treemap and hashmap (easy java solution) | using-treemap-and-hashmap-easy-java-solu-i8td | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | dpasala | NORMAL | 2025-04-05T04:39:24.141790+00:00 | 2025-04-05T04:39:24.141790+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Java'] | 0 |
online-election | Java TreeMap Based Solution | java-treemap-based-solution-by-sachinece-7u2d | IntuitionUse TreeMap to solve this problem.Approach
Maintain the Vote Counts of Persons in HashMap
Parallely Keep Track of the highest Voted person till the tim | sachineceuvce | NORMAL | 2025-04-01T17:26:09.122530+00:00 | 2025-04-01T17:26:09.122530+00:00 | 3 | false | # Intuition
Use TreeMap to solve this problem.
# Approach
1. Maintain the Vote Counts of Persons in HashMap
2. Parallely Keep Track of the highest Voted person till the time
3. Maintain TreeMap with , Time as Key , and Person With Highest Vote count at that point as value , and this treemap will be sorted based on tim... | 0 | 0 | ['Java'] | 0 |
online-election | Solution using TreeSet (don't need to write binary search when we already have TreeSet library) | solution-using-treeset-dont-need-to-writ-3v0n | Code | himanshu40makkar | NORMAL | 2025-03-29T19:31:04.551161+00:00 | 2025-03-29T19:31:04.551161+00:00 | 3 | false |
# Code
```java []
class Pair {
int person, timestamp;
Pair(int person, int timestamp) {
this.person = person;
this.timestamp = timestamp;
}
public String toString() {
return person+":"+timestamp;
}
}
class TopVotedCandidate {
TreeSet<Pair> ts;
public TopVotedCandida... | 0 | 0 | ['Java'] | 0 |
online-election | intuitive easy solution java | intuitive-easy-solution-java-by-panic08-4ylb | Code | panic08 | NORMAL | 2025-03-22T19:28:36.258378+00:00 | 2025-03-22T19:28:36.258378+00:00 | 4 | false |
# Code
```java []
class TopVotedCandidate {
private final TreeMap<Integer, Integer> timePersonMap;
public TopVotedCandidate(int[] persons, int[] times) {
this.timePersonMap = new TreeMap<>();
int[] personsVote = new int[persons.length];
int max = -1;
int maxPerson = -1;
... | 0 | 0 | ['Java'] | 0 |
online-election | go 1.21, clean code | go-121-clean-code-by-colix-nxf8 | null | colix | NORMAL | 2025-03-12T09:07:58.238932+00:00 | 2025-03-12T09:07:58.238932+00:00 | 6 | false | ```golang []
type TopVotedCandidate struct {
times []int
leaders []int
}
func Constructor(persons []int, times []int) TopVotedCandidate {
voteCount, leaders := make(map[int]int), make([]int, len(times))
maxVotes, leader := 0, -1
for i, person := range persons {
voteCount[person]++
if voteCount[person] >= ma... | 0 | 0 | ['Go'] | 0 |
online-election | Online Election | online-election-by-ansh1707-1b0q | Complexity
Time complexity: O(N)
Space complexity: O(1)
Code | Ansh1707 | NORMAL | 2025-02-19T05:14:07.870379+00:00 | 2025-02-19T05:14:07.870379+00:00 | 10 | false |
# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```python []
import bisect
from collections import defaultdict
class TopVotedCandidate(object):
def __init__(self, persons, times):
... | 0 | 0 | ['Array', 'Binary Search', 'Design', 'Python'] | 0 |
online-election | Beginner Friendly | C++ | beginner-friendly-c-by-ayushkokande-bnrb | IntuitionAt first glance, using a priority queue to track the leading voter might seem intuitive. However, consider scenarios where votes come in ascending or d | ayushkokande | NORMAL | 2025-02-16T06:13:53.871963+00:00 | 2025-02-16T06:14:46.407005+00:00 | 26 | false | # Intuition
At first glance, using a priority queue to track the leading voter might seem intuitive. However, consider scenarios where votes come in ascending or descending order. A priority queue approach would fail here because maintaining vote counts would require popping all elements, leading to an O(n) operation p... | 0 | 0 | ['C++'] | 0 |
online-election | Simple, Fast, Easy to understand, C++ | simple-fast-easy-to-understand-c-by-bilb-zwli | Approach ExplanationI use this free website to learn C++
https://www.cppexpert.online/This problem requires designing a data structure that efficiently determin | bilbobilley | NORMAL | 2025-02-15T10:31:44.502654+00:00 | 2025-02-15T10:31:44.502654+00:00 | 15 | false | Approach Explanation
I use this free website to learn C++
https://www.cppexpert.online/
This problem requires designing a data structure that efficiently determines the leading candidate at any given time t based on a series of votes.
1. Precompute Leader at Each Time
We maintain a map (person_counts) to keep track ... | 0 | 0 | ['C++'] | 0 |
online-election | C++ binary search solution | c-binary-search-solution-by-nguyenchiemm-hmk8 | null | nguyenchiemminhvu | NORMAL | 2025-01-22T08:21:39.174532+00:00 | 2025-01-22T08:21:39.174532+00:00 | 18 | false | ```
class TopVotedCandidate
{
public:
TopVotedCandidate(vector<int>& persons, vector<int>& times)
{
this->times = std::move(times);
int cur_elected = -1;
int max_election = 0;
timeline.resize(persons.size());
std::fill(timeline.begin(), timeline.end(), 0);
std::u... | 0 | 0 | ['C++'] | 0 |
online-election | 911. Online Election | 911-online-election-by-g8xd0qpqty-6r05 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-11T11:26:01.008081+00:00 | 2025-01-11T11:26:01.008081+00:00 | 18 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python3'] | 0 |
online-election | Easy Python Solution | easy-python-solution-by-sb012-orr8 | Code | sb012 | NORMAL | 2025-01-08T00:58:03.851715+00:00 | 2025-01-08T00:58:03.851715+00:00 | 21 | false | # Code
```python3 []
from collections import Counter
class TopVotedCandidate:
def __init__(self, persons: List[int], times: List[int]):
self.times = times
self.maxVotes = []
seen = Counter([])
maxi = -1
for i in persons:
seen[i] += 1
if seen[i] >= ... | 0 | 0 | ['Python3'] | 0 |
online-election | Heap + Lazy delete | heap-lazy-delete-by-psg_lgd_ana-2d13 | IntuitionWe can use a heap to maintain the most voted candidate at any given time. However, modifying any given candidate in a heap is very challenging.Approach | PSG_LGD_Ana | NORMAL | 2024-12-25T02:09:00.935440+00:00 | 2024-12-25T02:09:00.935440+00:00 | 6 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We can use a heap to maintain the most voted candidate at any given time. However, modifying any given candidate in a heap is very challenging.
# Approach
<!-- Describe your approach to solving the problem. -->
In fact, we don't need to m... | 0 | 0 | ['Python3'] | 0 |
online-election | array & dictionary. > 83% | array-dictionary-83-by-kapoorabinav-xuiy | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | kapoorabinav | NORMAL | 2024-12-20T12:00:07.926676+00:00 | 2024-12-20T12:00:07.926676+00:00 | 15 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C#'] | 0 |
online-election | Java soln - Binary search | java-soln-binary-search-by-saigopin-5kuh | Intuitionin this problem, we got to return who's leading at a given point of time. for that first we initialize an int[] leading that keeps track of leading can | Saigopin | NORMAL | 2024-12-16T22:53:36.729732+00:00 | 2024-12-16T22:53:36.729732+00:00 | 11 | false | # Intuition\nin this problem, we got to return who\'s leading at a given point of time. for that first we initialize an int[] leading that keeps track of leading candidate at a given point of time. for that we keep counting votes until that given point of time. once int[] leading is created, we use Binary search to fin... | 0 | 0 | ['Java'] | 0 |
online-election | Beats 100% | beats-100-by-jzylkin-t71n | Intuition\nThis was solved by just modeling exactly what happens. We iterate through each unit of time while keeping a leaderboard and updating it when a new ca | jzylkin | NORMAL | 2024-11-12T08:40:19.221156+00:00 | 2024-11-12T08:40:19.221186+00:00 | 21 | false | # Intuition\nThis was solved by just modeling exactly what happens. We iterate through each unit of time while keeping a leaderboard and updating it when a new candidate gets into the lead. We also keep track of each candidate\'s current vote tally to figure out when the candidate will be leading. \n\n# Approach\nUse a... | 0 | 0 | ['C++'] | 0 |
online-election | TypeScript / JavaScript solution using Binary Search | typescript-javascript-solution-using-bin-x1as | Intuition\n Describe your first thoughts on how to solve this problem. \nWe are given the fact that we need to figure out who is a leader at a specific time per | htndev | NORMAL | 2024-10-13T19:44:39.620919+00:00 | 2024-10-13T19:44:39.620941+00:00 | 16 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe are given the fact that we need to figure out who is a leader at a specific time period. If you even witnessed a real election race, you would see a graph with the difference of votes. We have a special condition that the winner is a p... | 0 | 0 | ['Array', 'Binary Search', 'TypeScript', 'JavaScript'] | 0 |
online-election | C++ || Map & done | c-map-done-by-garvit_17-47on | Intuition\nreturn (--m.upper_bound(t))->second ,putting upper_bound in bracket is imp guess why?\n\n# Approach\n Describe your approach to solving the problem. | garvit_17 | NORMAL | 2024-10-06T20:44:35.177916+00:00 | 2024-10-06T20:44:35.177936+00:00 | 18 | false | # Intuition\nreturn (--m.upper_bound(t))->second ,putting upper_bound in bracket is imp guess why?\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here... | 0 | 0 | ['C++'] | 0 |
online-election | EASY | TreeMap | ~20 lines | easy-treemap-20-lines-by-maheshs-fl8e | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n Initialize: Keep track | maheshs | NORMAL | 2024-09-27T23:02:43.179538+00:00 | 2024-09-27T23:02:43.179578+00:00 | 14 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* Initialize: Keep track of maxVotes per person over times and store in to \ntreeMap\n* Serve answer from TreeMap\n\n# Complexity\n- Time complexity:\n<!-- Add your ti... | 0 | 0 | ['Java'] | 0 |
online-election | Online Election | online-election-by-kuppapramod-i54k | \n\n# Complexity\n- Time complexity:\nO(N+log(N))\n- Space complexity:\nO(N)\n# Code\njava []\nclass TopVotedCandidate {\n private Map<Integer,Integer> leade | msdpramod | NORMAL | 2024-09-16T11:27:42.472469+00:00 | 2024-09-16T11:27:42.472495+00:00 | 3 | false | \n\n# Complexity\n- Time complexity:\nO(N+log(N))\n- Space complexity:\nO(N)\n# Code\n```java []\nclass TopVotedCandidate {\n private Map<Integer,Integer> leaderAtGivenTime;\n private int[] times;\n public TopVotedCandidate(int[] persons, int[] times) {\n this.leaderAtGivenTime= new HashMap<>();\n ... | 0 | 0 | ['Java'] | 0 |
online-election | JAVA | java-by-abhiguptanitb-nkw2 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | abhiguptanitb | NORMAL | 2024-09-13T02:31:02.469020+00:00 | 2024-09-13T02:31:02.469049+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 0 |
online-election | Array Traversal | array-traversal-by-94madhu94-o9jb | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | 94madhu94 | NORMAL | 2024-09-10T09:46:42.145251+00:00 | 2024-09-10T09:46:42.145274+00:00 | 13 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n- init: O(N) where N = len(times)\n- q: O(N) where N = len(times)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space... | 0 | 0 | ['Python3'] | 0 |
online-election | Array Traversal | array-traversal-by-94madhu94-gewu | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | 94madhu94 | NORMAL | 2024-09-10T09:40:12.333301+00:00 | 2024-09-10T09:40:12.333328+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Array', 'Hash Table', 'Python3'] | 0 |
online-election | Simple Array traversal | simple-array-traversal-by-94madhu94-eyyy | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | 94madhu94 | NORMAL | 2024-09-10T08:53:25.000255+00:00 | 2024-09-10T08:53:25.000278+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\ninit: O(N) where N is len(times)\n\n- Space complexity:\n<!-- Add your space... | 0 | 0 | ['Python3'] | 0 |
online-election | Binary Search | binary-search-by-stalebii-ik6m | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | stalebii | NORMAL | 2024-08-22T20:03:07.507485+00:00 | 2024-08-22T20:03:07.507510+00:00 | 21 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)... | 0 | 0 | ['Array', 'Hash Table', 'Binary Search', 'Design', 'Python3'] | 0 |
online-election | [Java] ✅ BinarySearch ✅ FAST ✅ CLEAN CODE ✅ CLEAR EXPLANATIONS | java-binarysearch-fast-clean-code-clear-im2vi | Approach\n1. Times[] is sorted in ASC. From the perspective, traversing it in this order can help you determine who had the max votes at each time.\n2. Use a cl | StefanelStan | NORMAL | 2024-08-16T08:10:12.544554+00:00 | 2024-08-16T08:10:12.544587+00:00 | 9 | false | # Approach\n1. Times[] is sorted in ASC. From the perspective, traversing it in this order can help you determine who had the max votes at each time.\n2. Use a class VotingStatus(time, person) and an array of it to hold the statuses for each time[i].\n3. Traverse time and keep track of max votes / person[i]. Set the Vo... | 0 | 0 | ['Java'] | 0 |
online-election | MOST EASIEST CODE CPP || WITH EXPLAINATION | most-easiest-code-cpp-with-explaination-3jfte | Intuition\nFirstly understand the problem, at each time there will be a voter, at for each time in times array we have to calculate who is the winner for that t | CheetahSort | NORMAL | 2024-08-08T07:38:06.729626+00:00 | 2024-08-08T07:38:06.729654+00:00 | 42 | false | # Intuition\nFirstly understand the problem, at each time there will be a voter, at for each time in times array we have to calculate who is the winner for that times[i](winner will be the one who has most vote till now, if two candidates have same votes than the one who recieved a vote more recently).\n1.we have to pr... | 0 | 0 | ['Array', 'Binary Search', 'C++'] | 0 |
search-suggestions-system | [C++/Java/Python] Sort and Binary Search the Prefix | cjavapython-sort-and-binary-search-the-p-hlpr | Intuition\nIn a sorted list of words,\nfor any word A[i],\nall its sugested words must following this word in the list.\n\nFor example, if A[i] is a prefix of A | lee215 | NORMAL | 2019-11-24T16:57:25.294704+00:00 | 2020-02-04T17:10:11.312547+00:00 | 71,591 | false | ## **Intuition**\nIn a sorted list of words,\nfor any word `A[i]`,\nall its sugested words must following this word in the list.\n\nFor example, if `A[i]` is a prefix of `A[j]`,\nA[i] must be the prefix of `A[i + 1], A[i + 2], ..., A[j]`\n\n## **Explanation**\nWith this observation,\nwe can binary search the position o... | 553 | 6 | [] | 67 |
search-suggestions-system | [Python] Trie + sort / Trie + Heap | python-trie-sort-trie-heap-by-ztonege-eo2s | Trie + Sort\nSort\nn = number of charcters in the products list\nTime: O(nlog(n))\nBuild Trie\nk = 3\nm = number of characters in the longest product\nTime: O(n | ztonege | NORMAL | 2020-02-14T13:55:46.183644+00:00 | 2020-02-14T14:06:28.548995+00:00 | 18,007 | false | # **Trie + Sort**\n**Sort**\nn = number of charcters in the products list\nTime: O(nlog(n))\n**Build Trie**\nk = 3\nm = number of characters in the longest product\nTime: O(n)\nSpace: O(nkm)\n**Output Result**\ns = number of characters in searchword\nTime: O(s)\nSpace: O(sk)\n```\nclass Solution:\n def suggestedProd... | 361 | 1 | [] | 28 |
search-suggestions-system | [Java/Python 3] Simple Trie and Binary Search codes w/ comment and brief analysis. | javapython-3-simple-trie-and-binary-sear-u9pl | Q & A:\nQ1: In method 1, why we needs two checks on root whther it is null as here:\n\n if (root != null) // if current Trie is NOT null.\n | rock | NORMAL | 2019-11-24T04:02:52.866359+00:00 | 2020-12-16T19:49:28.502921+00:00 | 31,633 | false | **Q & A:**\nQ1: In method 1, why we needs two checks on root whther it is null as here:\n```\n if (root != null) // if current Trie is NOT null.\n root = root.sub[c - \'a\'];\n ans.add(root == null ? Arrays.asList() : root.suggestion); // add it if there exist products with current ... | 203 | 4 | [] | 36 |
search-suggestions-system | [C++/Python] 3 solutions - Clean & Concise | cpython-3-solutions-clean-concise-by-hie-djxy | \u2714\uFE0F Solution 1: Sorting & Two pointer\n- Sorting our array of string products by increasing lexigographically order.\n- Using two pointer startIndex an | hiepit | NORMAL | 2021-05-31T09:37:08.576468+00:00 | 2021-10-25T13:41:25.932437+00:00 | 11,039 | false | **\u2714\uFE0F Solution 1: Sorting & Two pointer**\n- Sorting our array of string `products` by increasing lexigographically order.\n- Using two pointer `startIndex` and `endIndex` to filter `products` that match characters with their positions so far.\n- Collect nearest 3 `products` in range `[startIndex, endIndex]`.\... | 177 | 16 | [] | 13 |
search-suggestions-system | Java Priority Queue No Sort or Trie | java-priority-queue-no-sort-or-trie-by-g-bxvg | I found much more intuitive to iterate through every substring (0, k) of S asking each word in the product array if it starts with the substring, if it does, I | gregorioospina | NORMAL | 2020-01-05T21:34:05.075674+00:00 | 2020-01-05T21:34:05.075710+00:00 | 11,554 | false | I found much more intuitive to iterate through every substring (0, k) of S asking each word in the product array if it starts with the substring, if it does, I add it to a PriorityQueue which is comparing lexographhically, that way you just need to poll() 3 times to find the most accurate results.\n```\nclass Solution ... | 110 | 0 | ['Heap (Priority Queue)', 'Java'] | 26 |
search-suggestions-system | [Python] Short sort + 2 pointers, explained | python-short-sort-2-pointers-explained-b-ng4y | One way to solve this problem is tries, but I think it can be a bit overkill for medium difficulty quesion, so I prefer some other idea. \n\nWe can sort all our | dbabichev | NORMAL | 2021-05-31T10:06:50.467894+00:00 | 2021-05-31T10:06:50.467955+00:00 | 2,960 | false | One way to solve this problem is tries, but I think it can be a bit overkill for medium difficulty quesion, so I prefer some other idea. \n\nWe can sort all our words and use two pointers idea. Then we add letter by letter from our word `W` (originally it was `searchWord`, I renamed it for more consice code) and adjust... | 92 | 15 | ['Two Pointers', 'Sorting'] | 6 |
search-suggestions-system | Java, trie, explained, clean code, 14ms | java-trie-explained-clean-code-14ms-by-g-amhq | We can use a special kind of trie for this problem. Instead of keeping words in the bottom (last) node for each word we do the other way around - keep word in e | gthor10 | NORMAL | 2019-11-30T05:15:29.796382+00:00 | 2020-06-02T04:21:49.389850+00:00 | 8,556 | false | We can use a special kind of trie for this problem. Instead of keeping words in the bottom (last) node for each word we do the other way around - keep word in every node starting from the first character. This way we can immidiately get all words for the current character without traversing the trie. This way we\'re ma... | 78 | 1 | ['Trie', 'Java'] | 8 |
search-suggestions-system | A More Intuitive Solution | JAVA Explained | a-more-intuitive-solution-java-explained-cu5k | Logic:\nThe approach I had in mind is quite simple! All we need to do is add each product to a prefix trie and then perform a depth-first-search through the tri | ciote | NORMAL | 2022-06-19T01:15:03.206232+00:00 | 2022-06-19T01:47:23.774905+00:00 | 6,054 | false | ### Logic:\nThe approach I had in mind is quite simple! All we need to do is add each product to a prefix trie and then perform a depth-first-search through the trie for each character of our `searchWord` to add our three-word suggestions. The key bit of implementation here is that we\'re keeping track of those suggest... | 60 | 0 | ['Trie', 'Java'] | 7 |
search-suggestions-system | [C++] Easy sort (No trie) O(1) Space | c-easy-sort-no-trie-o1-space-by-phoenixd-juuc | Observation\nIf the strings are sorted we can binary search to get the first word that has the same prefix, we can then just check the next 2 words to see if th | phoenixdd | NORMAL | 2019-11-24T04:01:34.161704+00:00 | 2019-11-27T06:03:07.675566+00:00 | 6,863 | false | **Observation**\nIf the strings are sorted we can binary search to get the first word that has the same prefix, we can then just check the next 2 words to see if they have the same prefix or not.\n\n**Solution**\n```c++\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, s... | 58 | 4 | [] | 5 |
search-suggestions-system | JS, Python, Java, C++ | Easy Iterative Solution w/ Explanation | js-python-java-c-easy-iterative-solution-h0na | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-05-31T09:43:33.935362+00:00 | 2021-05-31T11:36:15.261484+00:00 | 4,479 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nDespite the fact that the clues suggest a **binary search** and a **trie**, the optimal solution to this problem needs neither. The substrings... | 56 | 6 | ['C', 'Python', 'Java', 'JavaScript'] | 6 |
search-suggestions-system | [Python] A simple approach without using Trie | python-a-simple-approach-without-using-t-wugu | Solution\n\nUse sort and list comprehension.\n\npython\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str] | crosserclaws | NORMAL | 2019-11-24T13:08:13.871636+00:00 | 2023-11-08T16:01:44.537236+00:00 | 6,705 | false | # Solution\n\nUse sort and list comprehension.\n\n```python\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n list_ = []\n products.sort()\n for i, c in enumerate(searchWord):\n products = [ p for p in products if len(p) > i and... | 51 | 2 | ['Sorting', 'Python', 'Python3'] | 9 |
search-suggestions-system | ✅C++ || All testcase passed->2 SOLUTION -> 10 LINES CODE | c-all-testcase-passed-2-solution-10-line-gw7l | \u2705APPROACH : 1\n# VERY EASY SOLUTION -> NO THINKING NEEDED JUST DO WHAT IS SAID IN QUESTION-->\n sort the string list\n create a temp vector to store the an | rab8it | NORMAL | 2022-06-19T05:25:08.312820+00:00 | 2022-06-19T05:26:51.804879+00:00 | 3,930 | false | **\u2705APPROACH : 1**\n# VERY EASY SOLUTION -> NO THINKING NEEDED JUST DO WHAT IS SAID IN QUESTION-->\n* ***sort the string list***\n* ***create a temp vector to store the answer in each stage and then push it back***\n\n```\nvector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n ... | 50 | 0 | ['Binary Search', 'C', 'Sorting', 'Binary Tree', 'C++'] | 5 |
search-suggestions-system | Python 3 | Two Methods (Sort, Trie) | Explanation | python-3-two-methods-sort-trie-explanati-6ch6 | Approach \#1. Sort + Binary Search\n- Sort A\n- For each prefix, do binary search\n- Get 3 words from the index and check if it matches the prefix\n\nclass Solu | idontknoooo | NORMAL | 2020-09-26T03:29:57.081923+00:00 | 2020-10-15T19:43:10.955044+00:00 | 6,400 | false | ### Approach \\#1. Sort + Binary Search\n- Sort `A`\n- For each prefix, do binary search\n- Get 3 words from the index and check if it matches the prefix\n```\nclass Solution:\n def suggestedProducts(self, A: List[str], searchWord: str) -> List[List[str]]:\n A.sort()\n res, cur = [], \'\'\n for ... | 50 | 0 | ['Binary Search', 'Trie', 'Sorting', 'Python', 'Python3'] | 4 |
search-suggestions-system | Python Trie Solution | python-trie-solution-by-otoc-sptv | Please see and vote for my solutions for\n208. Implement Trie (Prefix Tree)\n1233. Remove Sub-Folders from the Filesystem\n1032. Stream of Characters\n1268. Sea | otoc | NORMAL | 2019-11-24T04:06:06.446646+00:00 | 2019-11-24T06:17:40.165415+00:00 | 6,817 | false | Please see and vote for my solutions for\n[208. Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/discuss/320224/Simple-Python-solution)\n[1233. Remove Sub-Folders from the Filesystem](https://leetcode.com/problems/remove-sub-folders-from-the-filesystem/discuss/409075/standard-pytho... | 45 | 4 | [] | 5 |
search-suggestions-system | [Python] Intuitive trie solution with detailed explanation | python-intuitive-trie-solution-with-deta-d683 | Algorithm:\n- To allow the auto-completion/word-suggestion feature, create your typical Trie node class with an extra attribute: \n\nclass Node:\n def __init | Hieroglyphs | NORMAL | 2020-02-10T22:13:46.537458+00:00 | 2020-02-10T22:34:34.273146+00:00 | 1,936 | false | **Algorithm:**\n- To allow the auto-completion/word-suggestion feature, create your typical Trie node class with an extra attribute: \n```\nclass Node:\n def __init__(self, val):\n self.val = val\n self.children = {}\n self.suggestions = []\n```\n- While building the trie, we insert a new charac... | 44 | 0 | ['Trie', 'Python'] | 4 |
search-suggestions-system | C++ Three Way Solution With Picture(arrary sort 、Trie(hash+array)、Trie(hash+heap)) | c-three-way-solution-with-picturearrary-djt4k | \u4E2D\u6587\u8BE6\u7EC6\u89C1 1268. Search Suggestions System\n\n## array sort\n\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vecto | xiongqiangcs | NORMAL | 2019-12-02T08:07:04.099131+00:00 | 2019-12-02T17:20:02.897773+00:00 | 3,810 | false | \u4E2D\u6587\u8BE6\u7EC6\u89C1 [1268. Search Suggestions System](https://www.jianshu.com/p/8284decf7077)\n\n## array sort\n```\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(), products.end());\n vector<vector<s... | 44 | 0 | [] | 3 |
search-suggestions-system | 💡JavaScript Solution - Trie & Sort | javascript-solution-trie-sort-by-aminick-winl | The idea - Trie\n1. Sort the products\n2. Build a trie, add a sug property where it stores the suggested products for the current character.\njavascript\n/**\n | aminick | NORMAL | 2020-02-04T07:56:19.672617+00:00 | 2020-02-04T07:56:19.672655+00:00 | 2,592 | false | ### The idea - Trie\n1. Sort the products\n2. Build a `trie`, add a `sug` property where it stores the suggested products for the current character.\n``` javascript\n/**\n * @param {string[]} products\n * @param {string} searchWord\n * @return {string[][]}\n */\nvar suggestedProductsTrie = function(products, searchWord... | 37 | 0 | ['JavaScript'] | 7 |
search-suggestions-system | Python Easy 2 Approaches | python-easy-2-approaches-by-constantine7-5cwu | The solution that I have implemented is brute force. With each iteration, I will update the list of available words using indices.\n\n## Example\n\n# sort the p | constantine786 | NORMAL | 2022-06-19T00:42:47.210592+00:00 | 2022-06-19T00:56:23.299523+00:00 | 6,506 | false | The solution that I have implemented is brute force. With each iteration, I will update the list of available words using `indices`.\n\n## **Example**\n```\n# sort the products\nproducts = ["mobile","moneypot","monitor","mouse","mousepad"] \nsearchWord = "mouse"\n```\n\nAfter each iteration, the contents of products w... | 33 | 0 | ['Python', 'Python3'] | 4 |
search-suggestions-system | Lessons learned | lessons-learned-by-vyshnavkr-7v5n | A good problem that could be solved in three approaches.\n\nPasting my original comment below\nMy Thoughts:\n1. Key points that could be applied to other proble | vyshnavkr | NORMAL | 2021-01-19T05:58:51.096055+00:00 | 2024-02-19T17:55:00.496512+00:00 | 894 | false | A good problem that could be solved in three approaches.\n\n[Pasting my original comment below](https://leetcode.com/problems/search-suggestions-system/solution/822794)\n**My Thoughts**:\n1. **Key points that could be applied to other problems**:\n* \'Lexographical\': This should hint you the data requires some orderin... | 31 | 0 | [] | 3 |
search-suggestions-system | [Java] super easy and clean solution, Beats 95% time and 100% space | java-super-easy-and-clean-solution-beats-zxw1 | \nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> finalResult = new ArrayL | maneeshreddy | NORMAL | 2020-02-16T09:47:03.908047+00:00 | 2020-03-14T08:51:45.825365+00:00 | 3,386 | false | ```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> finalResult = new ArrayList();\n if (products == null || products.length == 0 || searchWord == null || searchWord.isEmpty()) {\n return finalResult;\n }\n ... | 30 | 0 | ['Java'] | 10 |
search-suggestions-system | C++ || Binary Search Clean Code, Explained 94 ms TC: O(NlogN), SC: O(NlogN) | c-binary-search-clean-code-explained-94-kcbh3 | Intuition\nSorted list of array ,for any word A[i], all its sugested words must following this word in the list.\n\nFor example, if A[i] is a prefix of A[j],\nA | DarshanAgarwal95 | NORMAL | 2022-06-19T01:37:31.521199+00:00 | 2022-06-19T01:37:31.521240+00:00 | 4,621 | false | **Intuition**\nSorted list of array ,for any word A[i], all its sugested words must following this word in the list.\n\nFor example, if A[i] is a prefix of A[j],\nA[i] must be the prefix of A[i + 1], A[i + 2], ..., A[j]\n\n**Explanation**\nWith this observation,\nwe can binary search the position of each prefix of sear... | 29 | 0 | ['Trie', 'C', 'Binary Tree'] | 3 |
search-suggestions-system | Search Suggestions System | JS, Python, Java, C++ | Easy Iterative Solution w/ Explanation | search-suggestions-system-js-python-java-e4u6 | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-05-31T09:44:28.412485+00:00 | 2021-05-31T11:36:24.967635+00:00 | 960 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nDespite the fact that the clues suggest a **binary search** and a **trie**, the optimal solution to this problem needs neither. The substrings... | 26 | 0 | [] | 2 |
search-suggestions-system | [C++] Trie and Binary search solution. [Detailed Explanation] | c-trie-and-binary-search-solution-detail-d16z | SOLUTION 1: Using Binary Search\n// Using Binary search\n // TC: Binary Search + Sorting\n // O(L ^ 2 * logn + m*nlogn), L: length of word to find, m | cryptx_ | NORMAL | 2020-07-04T04:01:18.105031+00:00 | 2020-07-04T04:01:18.105083+00:00 | 3,258 | false | **SOLUTION 1: Using Binary Search**\n```// Using Binary search\n // TC: Binary Search + Sorting\n // O(L ^ 2 * logn + m*nlogn), L: length of word to find, m: length of longest word\n // For binary search: 1char: logn\n // 2chars: 2 * logn\n // ... L chars: L ... | 25 | 1 | ['Trie', 'C', 'Binary Tree', 'C++'] | 3 |
search-suggestions-system | Simple Trie C++ solution | simple-trie-c-solution-by-ankurharitosh-upar | \nclass Solution {\npublic:\n class Trie{\n public:\n vector<Trie*> children;\n bool isEnd;\n \n Trie(){\n chil | ankurharitosh | NORMAL | 2020-08-28T13:21:05.525548+00:00 | 2020-08-28T15:04:08.674256+00:00 | 2,124 | false | ```\nclass Solution {\npublic:\n class Trie{\n public:\n vector<Trie*> children;\n bool isEnd;\n \n Trie(){\n children = vector<Trie*> (26, nullptr);\n isEnd=false;\n }\n \n void addWord(string word){\n Trie* node=this;\n ... | 24 | 1 | ['Trie', 'C', 'C++'] | 0 |
search-suggestions-system | C++ Sort | c-sort-by-votrubac-8qnh | Sort all products. Then do binary search for substrings of increasing size, taking up to three words.\n\nvector<vector<string>> suggestedProducts(vector<string> | votrubac | NORMAL | 2019-11-24T06:44:50.682548+00:00 | 2019-12-02T19:57:20.311025+00:00 | 1,697 | false | Sort all products. Then do binary search for substrings of increasing size, taking up to three words.\n```\nvector<vector<string>> suggestedProducts(vector<string>& ps, string word) {\n sort(begin(ps), end(ps));\n vector<vector<string>> res(word.size());\n for (auto l = 1; l <= word.size(); ++l) {\n aut... | 19 | 2 | [] | 4 |
search-suggestions-system | ✅C++ || Using Map || Easy to Understand || 🗓️ Daily LeetCoding Challenge June, Day 19 | c-using-map-easy-to-understand-daily-lee-hgj1 | Please Upvote If It Helps \uD83D\uDE0A\n\n\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord | mayanksamadhiya12345 | NORMAL | 2022-06-19T05:17:11.749665+00:00 | 2022-06-19T05:23:26.798996+00:00 | 1,079 | false | **Please Upvote If It Helps \uD83D\uDE0A**\n\n```\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) \n {\n // first sort the given products string\n sort(products.begin(), products.end());\n \n // it will store the strin... | 18 | 0 | [] | 4 |
search-suggestions-system | c++ trie | c-trie-by-cxky-szts | \nstruct TrieNode {\n TrieNode *children[26] = {NULL};\n bool endOfWord = false;\n};\nclass Solution {\npublic:\n void insertWord(TrieNode *trie, strin | cxky | NORMAL | 2021-05-31T09:02:14.383483+00:00 | 2021-05-31T09:02:14.383525+00:00 | 1,099 | false | ```\nstruct TrieNode {\n TrieNode *children[26] = {NULL};\n bool endOfWord = false;\n};\nclass Solution {\npublic:\n void insertWord(TrieNode *trie, string &word) {\n for (char &c : word) {\n int index = c - \'a\';\n if (!trie->children[index])\n trie->children[index... | 18 | 1 | ['Trie', 'C'] | 4 |
search-suggestions-system | C++ Two Pointer Easy Solution | c-two-pointer-easy-solution-by-akakash55-q4fg | \nvector<vector<string>> suggestedProducts(vector<string>& products, string search) {\n sort(products.begin(),products.end());\n int l=0,r=product | akakash55 | NORMAL | 2022-06-19T03:43:44.485393+00:00 | 2022-06-19T03:43:44.485415+00:00 | 1,464 | false | ```\nvector<vector<string>> suggestedProducts(vector<string>& products, string search) {\n sort(products.begin(),products.end());\n int l=0,r=products.size()-1;\n vector<vector<string>> ans;\n for(int i=0;i<search.size();i++)\n {\n char ch=search[i];\n vector<str... | 14 | 0 | ['Two Pointers', 'C', 'C++'] | 3 |
search-suggestions-system | [Java] Trie Solution | java-trie-solution-by-manrajsingh007-n05w | ```\nclass TrieNode{\n\n\tchar data;\n\tTrieNode children[];\n boolean isTerminating;\n int count;\n\n\tpublic TrieNode(char data) {\n\t\tthis.data = data | manrajsingh007 | NORMAL | 2019-11-24T11:05:30.607313+00:00 | 2019-11-24T11:05:30.607346+00:00 | 3,965 | false | ```\nclass TrieNode{\n\n\tchar data;\n\tTrieNode children[];\n boolean isTerminating;\n int count;\n\n\tpublic TrieNode(char data) {\n\t\tthis.data = data;\n\t\tchildren = new TrieNode[26];\n this.isTerminating = false;\n this.count = 0;\n\t}\n}\n\npublic class Trie {\n\n\tpublic TrieNode root;\n\tp... | 14 | 1 | ['Trie'] | 1 |
search-suggestions-system | C# Trie solution | c-trie-solution-by-newbiecoder1-2gae | \npublic class TrieNode\n{\n public List<string> Suggestion;\n public TrieNode[] Children;\n public TrieNode()\n {\n Suggestion = new List<st | newbiecoder1 | NORMAL | 2020-04-17T00:35:23.172266+00:00 | 2020-04-17T00:45:59.927882+00:00 | 665 | false | ```\npublic class TrieNode\n{\n public List<string> Suggestion;\n public TrieNode[] Children;\n public TrieNode()\n {\n Suggestion = new List<string>();\n Children = new TrieNode[26];\n }\n}\n\npublic class Solution {\n public IList<IList<string>> SuggestedProducts(string[] products, str... | 13 | 0 | [] | 0 |
search-suggestions-system | Simple python short solution | simple-python-short-solution-by-mrdelhi-zrj7 | \nclass Solution(object):\n def suggestedProducts(self, products, searchWord):\n result = list() \n products.sort()\n for i in range(1, | mrdelhi | NORMAL | 2019-11-24T04:27:47.633724+00:00 | 2019-11-24T04:27:47.633770+00:00 | 1,141 | false | ```\nclass Solution(object):\n def suggestedProducts(self, products, searchWord):\n result = list() \n products.sort()\n for i in range(1, len(searchWord)+1):\n products = list(filter(lambda x: x.startswith(searchWord[:i]), products))\n result.append(products[:3])\n ... | 13 | 4 | [] | 1 |
search-suggestions-system | Python Trie Solution. Industry Level Code | python-trie-solution-industry-level-code-19cb | \nclass TreeNode:\n def __init__(self):\n self.children = [None]*26\n self.words = []\nclass Trie:\n def __init__(self):\n self.root | Kakashi_97 | NORMAL | 2022-06-19T06:53:45.242468+00:00 | 2022-06-19T06:54:30.329454+00:00 | 2,168 | false | ```\nclass TreeNode:\n def __init__(self):\n self.children = [None]*26\n self.words = []\nclass Trie:\n def __init__(self):\n self.root = TreeNode()\n def _getIndex(self,ch):\n return ord(ch)-ord(\'a\')\n def insert(self,word):\n cur_node = self.root\n for ch in wor... | 12 | 0 | ['Trie', 'Python', 'Python3'] | 4 |
search-suggestions-system | Python Trie Implementation | python-trie-implementation-by-ht_wang-292w | \nclass TrieNode:\n def __init__(self):\n self.chars={}\n self.wordList =[]\n \nclass Trie(object):\n def __init__(self):\n se | ht_wang | NORMAL | 2019-11-26T04:52:01.882846+00:00 | 2019-11-26T04:52:01.882881+00:00 | 534 | false | ```\nclass TrieNode:\n def __init__(self):\n self.chars={}\n self.wordList =[]\n \nclass Trie(object):\n def __init__(self):\n self.root = TrieNode()\n \n def addWord(self, word):\n node = self.root\n for c in word:\n if c not in node.chars:\n ... | 12 | 0 | [] | 1 |
search-suggestions-system | Two pointer approach | 99.17 percent faster | Explained | two-pointer-approach-9917-percent-faster-lmbd | Intuition\nInitially, the products array is sorted lexicographically to ensure that suggestions are not only correct but also presented in the smallest lexicogr | singhsauravsk | NORMAL | 2024-02-03T19:22:21.502338+00:00 | 2024-02-04T20:17:01.687596+00:00 | 1,549 | false | # Intuition\nInitially, the products array is sorted lexicographically to ensure that suggestions are not only correct but also presented in the smallest lexicographical order. This preparatory step is foundational because it aligns the product names in a sequence that simplifies subsequent operations.\n\nThe core of t... | 11 | 0 | ['Java'] | 3 |
search-suggestions-system | C#, Go, Python | Two approaches | c-go-python-two-approaches-by-sergiich-kchy | Code\n\n## Option 1\ncsharp [one]\npublic class Solution {\n public IList<IList<string>> SuggestedProducts(string[] products, string searchWord) {\n v | SergiiCh | NORMAL | 2023-11-24T05:26:37.543871+00:00 | 2023-11-24T05:26:37.543891+00:00 | 933 | false | # Code\n\n## Option 1\n``` csharp [one]\npublic class Solution {\n public IList<IList<string>> SuggestedProducts(string[] products, string searchWord) {\n var result = new List<IList<string>>();\n var previouse = products.OrderBy(it => it).ToList();\n for (var i = 0; i < searchWord.Length; i++)\... | 10 | 0 | ['Go', 'Python3', 'C#'] | 4 |
search-suggestions-system | Python3 Simple | python3-simple-by-kanukam123-43m7 | \nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n """\n sort words\n l | kanukam123 | NORMAL | 2022-01-23T02:43:02.268674+00:00 | 2022-01-23T02:43:02.268716+00:00 | 518 | false | ```\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n """\n sort words\n loop through chars of searchWord\n \n if the index being looked at on searchWord is equal to word in product, add prod... | 10 | 0 | ['Python'] | 2 |
search-suggestions-system | C# solution - filter set | c-solution-filter-set-by-rnoack-rnrp | I\'m surprised I didn\'t see a solution like this in the discussion even in other languages but I maybe didn\'t look hard enough?\n\nA lot of people have soluti | rnoack | NORMAL | 2020-03-30T01:25:18.780030+00:00 | 2020-03-30T01:25:18.780077+00:00 | 396 | false | I\'m surprised I didn\'t see a solution like this in the discussion even in other languages but I maybe didn\'t look hard enough?\n\nA lot of people have solutions using binary search which does seem smart, and probably good for the first search...\nBut in all of these solutions, I see people doing the binary search at... | 10 | 0 | [] | 0 |
search-suggestions-system | [JavaScript] Easy to understand - 2 solutions - binary search with O(1) space | javascript-easy-to-understand-2-solution-7ua4 | SOLUTION 1\n\nIt\'s a pretty straight forward solution. We traversal the products to match the prefix and finally get the result.\nI got 92ms as the best for th | poppinlp | NORMAL | 2019-11-30T06:50:35.994474+00:00 | 2019-11-30T06:54:59.582518+00:00 | 1,231 | false | ### SOLUTION 1\n\nIt\'s a pretty straight forward solution. We traversal the products to match the prefix and finally get the result.\nI got 92ms as the best for this strategy. And here are some little optimizations:\n\n- update the product list for each search word since the suggestions for `searchWord.slice(0, x + 1)... | 10 | 0 | ['JavaScript'] | 0 |
search-suggestions-system | 🌲JavaScript Trie Solution | 🌲Trie + DFS | javascript-trie-solution-trie-dfs-by-lon-t1jq | \nclass TrieNode{\n constructor(){\n this.children = {}\n this.endWord = false\n this.wordStr = ""\n }\n \n // build Prefix Tre | lonelykite | NORMAL | 2022-06-20T03:48:21.997546+00:00 | 2022-11-06T04:10:59.388464+00:00 | 561 | false | ```\nclass TrieNode{\n constructor(){\n this.children = {}\n this.endWord = false\n this.wordStr = ""\n }\n \n // build Prefix Tree.\n insert(word){\n let cur = this\n for(const w of word){\n if(!cur.children[w]){\n cur.children[w] = new TrieNo... | 9 | 0 | ['Depth-First Search', 'Trie', 'JavaScript'] | 2 |
search-suggestions-system | Java using Trie - Similar to 425 Word Squares - Straightforward | java-using-trie-similar-to-425-word-squa-07pr | \nclass Solution {\n \n // making a trie containing a list of words starting at every node\n class Node {\n Node[] children;\n List<Strin | djoko9 | NORMAL | 2020-05-17T01:58:12.814349+00:00 | 2020-05-17T01:58:12.814383+00:00 | 1,013 | false | ```\nclass Solution {\n \n // making a trie containing a list of words starting at every node\n class Node {\n Node[] children;\n List<String> startsWith;\n Node() {\n children = new Node[26];\n startsWith = new ArrayList<>();\n }\n }\n \n // insertion... | 9 | 0 | ['Trie', 'Java'] | 0 |
search-suggestions-system | [C++] Trie | c-trie-by-hitgif-pr5l | cpp\nclass Node {\npublic:\n bool end;\n vector<Node *> ch;\n\t\n\t// Minimal storage\n Node(): end(false), ch(26, nullptr) {}\n};\n\nclass Trie {\npub | hitgif | NORMAL | 2019-12-17T18:59:11.245060+00:00 | 2019-12-17T19:00:30.515051+00:00 | 426 | false | ```cpp\nclass Node {\npublic:\n bool end;\n vector<Node *> ch;\n\t\n\t// Minimal storage\n Node(): end(false), ch(26, nullptr) {}\n};\n\nclass Trie {\npublic:\n Node *head = new Node();\n\n void addWord(string &s) {\n Node *cur = head;\n for (char c: s) {\n if (!cur->ch[c - \'a\'... | 9 | 0 | [] | 3 |
search-suggestions-system | Solution By Dare2Solve | Detailed Explanation | Clean Code | solution-by-dare2solve-detailed-explanat-hlm8 | Explanation []\nauthorslog.com/blog/yv5CR0BuC8\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& prod | Dare2Solve | NORMAL | 2024-08-26T07:16:10.951484+00:00 | 2024-08-26T07:16:10.951510+00:00 | 2,304 | false | ```Explanation []\nauthorslog.com/blog/yv5CR0BuC8\n```\n# Code\n\n```cpp []\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(), products.end());\n vector<vector<string>> ans;\n int left = 0, right = product... | 8 | 0 | ['Binary Search', 'Heap (Priority Queue)', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
search-suggestions-system | Python Intuitive Approach | Runtime 66.65% memory 47.63 | python-intuitive-approach-runtime-6665-m-xpph | So as we want lexicographically sorted words, I sorted the array,\nAfter that, I\'m storing the prefix and all possible words that sore the prefix.\nfinally I i | zeus-salazar | NORMAL | 2022-06-19T08:30:49.382548+00:00 | 2022-06-19T08:30:49.382585+00:00 | 277 | false | So as we want lexicographically sorted words, I **sorted the array**,\nAfter that, I\'m storing the prefix and all possible words that sore the prefix.\nfinally I iterated over the search string to to get the three "**minimum lexicographic matches**" for each character by doing a *look-up over my prefixes table* and st... | 8 | 0 | [] | 0 |
search-suggestions-system | 📌 Python3 solution using Trie an dfs | python3-solution-using-trie-an-dfs-by-da-hflo | \nfrom string import ascii_lowercase\n\nclass TriNode:\n def __init__(self, val):\n self.val = val\n self.next = [0]*26\n self.isLeaf = | dark_wolf_jss | NORMAL | 2022-06-25T06:15:23.288645+00:00 | 2022-06-25T06:15:23.288684+00:00 | 1,399 | false | ```\nfrom string import ascii_lowercase\n\nclass TriNode:\n def __init__(self, val):\n self.val = val\n self.next = [0]*26\n self.isLeaf = False\n\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n \n root = TriNode("")\n ... | 7 | 0 | ['Depth-First Search', 'Trie', 'Python3'] | 1 |
search-suggestions-system | [C++] Simple and Clean Brute force solution / Trie Solution | 90ms | c-simple-and-clean-brute-force-solution-j56ad | Brute Force Solution\n\n\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(p | sreedhar18161 | NORMAL | 2021-05-31T14:53:05.835958+00:00 | 2021-05-31T14:53:05.836004+00:00 | 615 | false | ### Brute Force Solution\n\n```\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(),products.end());\n vector<vector<string>> output;\n vector<string> temp,space,filtered;\n for(int i=0;i<searchWord.s... | 7 | 0 | ['Trie', 'C', 'Sorting', 'C++'] | 1 |
search-suggestions-system | Python 3, very simple solution | python-3-very-simple-solution-by-silvia4-efhv | Are the test cases not good enough? \nThis brute force solution is accepted and time is better than 80% and memory is better than 55% Python solutions.\nIt is N | silvia42 | NORMAL | 2021-05-31T13:55:42.775538+00:00 | 2021-05-31T14:02:21.188187+00:00 | 313 | false | Are the test cases not good enough? \nThis brute force solution is accepted and time is better than 80% and memory is better than 55% Python solutions.\nIt is NOT TRIE and I am not using binary search.\n\nSolution:\n1. We are sorting products in alphabethical order.\n2. We are creating a new list of products ```newProd... | 7 | 0 | [] | 0 |
search-suggestions-system | C++ Super Simple and Clean Solution, Sort + BS, Faster then 90% | c-super-simple-and-clean-solution-sort-b-gxcu | \nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n vector<vector<string>> res;\n | yehudisk | NORMAL | 2021-05-31T08:17:16.060606+00:00 | 2021-05-31T08:17:16.060632+00:00 | 333 | false | ```\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n vector<vector<string>> res;\n string prefix = "";\n auto i = products.begin(), it = i;\n int k;\n \n sort(products.begin(), products.end());\n \n... | 7 | 2 | ['C'] | 0 |
search-suggestions-system | [C++] Simple sort and binary search. | c-simple-sort-and-binary-search-by-vinay-r3fo | \nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n vector<vector<string>> res;\n | vinaykashyap | NORMAL | 2020-06-26T15:26:14.105392+00:00 | 2020-06-26T15:26:14.105434+00:00 | 654 | false | ```\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n vector<vector<string>> res;\n sort(products.begin(), products.end());\n int i, j, mid, low, high;\n for(i = 0; i < searchWord.size(); i++){\n string s = se... | 7 | 0 | ['C', 'Sorting', 'Binary Tree'] | 1 |
search-suggestions-system | Java Trie Solution(Using TreeSet) | java-trie-solutionusing-treeset-by-poorv-xbj3 | \nclass Node {\n private Node[] children;\n private TreeSet<String> list = new TreeSet<>();\n\n Node(String s) {\n children = ne | poorvank | NORMAL | 2019-11-28T14:31:30.784901+00:00 | 2019-11-28T14:31:30.784953+00:00 | 1,555 | false | ```\nclass Node {\n private Node[] children;\n private TreeSet<String> list = new TreeSet<>();\n\n Node(String s) {\n children = new Node[26];\n if(s!=null) {\n list.add(s);\n }\n }\n }\n\n Node root;\n public List<List<String>> sugges... | 7 | 0 | [] | 2 |
search-suggestions-system | Using java subsequence (very simple logic) | using-java-subsequence-very-simple-logic-pq0a | \n public List> suggestedProducts(String[] products, String searchWord) {\n List> results = new ArrayList<>();\n\n if(products == null || produ | banty | NORMAL | 2019-11-26T01:47:23.180247+00:00 | 2019-11-26T01:47:23.180294+00:00 | 821 | false | \n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> results = new ArrayList<>();\n\n if(products == null || products.length == 0) return results;\n\n\t\t// sort the products lexicographically\n Arrays.sort(products);\n\n for(int i = ... | 7 | 0 | [] | 1 |
search-suggestions-system | [Java] ✅Fastest Solution 97% || Sorting & Trie & Explaination | java-fastest-solution-97-sorting-trie-ex-ma0k | \n# Code\n\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> result = new L | deleted_user | NORMAL | 2022-11-09T07:04:32.385229+00:00 | 2022-11-09T07:05:28.536727+00:00 | 1,584 | false | \n# Code\n```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> result = new LinkedList<>();\n // sorting\n Arrays.sort(products);\n\n for (int i = 0; i < searchWord.length(); i++) result.add(new LinkedList<>());\n... | 6 | 0 | ['Java'] | 2 |
search-suggestions-system | Python Using Trie | python-using-trie-by-__aj-qmeu | \n\tclass Solution:\n\t\tdef suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n\t\t\tproducts.sort()\n\t\t\tobj = Trie()\n\t\t\ | __AJ__ | NORMAL | 2021-11-26T17:33:40.782159+00:00 | 2021-11-26T17:37:49.311147+00:00 | 728 | false | \n\tclass Solution:\n\t\tdef suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n\t\t\tproducts.sort()\n\t\t\tobj = Trie()\n\t\t\tfor product in products:\n\t\t\t\tobj.insert(product)\n\n\t\t\tfinal = []\n\t\t\tword = \'\'\n\t\t\tfor char in searchWord:\n\t\t\t\tword += char\n\t\t\t\tfina... | 6 | 0 | ['Depth-First Search', 'Trie', 'Python', 'Python3'] | 0 |
search-suggestions-system | [Python3] Simple And Readable solution | python3-simple-and-readable-solution-by-y3es0 | \nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n def get(string , arr):\n x = 0\ | VoidCupboard | NORMAL | 2021-05-31T11:01:56.947424+00:00 | 2021-05-31T11:01:56.947466+00:00 | 128 | false | ```\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n def get(string , arr):\n x = 0\n ans = []\n \n for i in arr:\n if(x == 3): break\n \n if(i.startswith(stri... | 6 | 1 | [] | 0 |
search-suggestions-system | Java Simple Solution | java-simple-solution-by-mayankbansal-u15j | ```\nclass Solution {\n public List> suggestedProducts(String[] products, String searchWord) {\n Arrays.sort(products);\n List> ans=new ArrayLi | mayankbansal | NORMAL | 2020-07-20T18:24:30.139418+00:00 | 2020-07-20T18:24:30.139483+00:00 | 326 | false | ```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n Arrays.sort(products);\n List<List<String>> ans=new ArrayList<>();\n\n for(int i=1;i<=searchWord.length();i++){\n String a=searchWord.substring(0,i);\n ans.add(new ... | 6 | 0 | [] | 2 |
search-suggestions-system | Python Simple Array + Binary Search Solution | python-simple-array-binary-search-soluti-adwb | For every char, iterating over the products and breaking after finding 3 products with the same prefix.\n\nclass Solution:\n def suggestedProducts(self, prod | faizulhai | NORMAL | 2020-06-18T08:26:16.697116+00:00 | 2020-06-18T15:14:34.018783+00:00 | 685 | false | For every char, iterating over the products and breaking after finding 3 products with the same prefix.\n```\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n res = []\n products.sort()\n for i, c in enumerate(searchWord):\n cou... | 6 | 0 | ['Python3'] | 0 |
search-suggestions-system | Python3 Trie Solution (Accepted) - an online solution | python3-trie-solution-accepted-an-online-x5d1 | isWord is an int instead of boolean here, aiming to deal with the duplicate word edge case.\n2. children is a 26-length array instead of a dict because we need | darrenfu42 | NORMAL | 2019-11-24T04:40:53.310752+00:00 | 2019-11-24T04:40:53.310787+00:00 | 969 | false | 1. `isWord` is an int instead of boolean here, aiming to deal with the duplicate word edge case.\n2. `children` is a 26-length array instead of a dict because we need to sort in lexicographical order. Luckily, all lowercase characters in this problem. \n3. `suggestions` to store the top K suggested words in every TrieN... | 6 | 0 | ['Trie', 'Python', 'Python3'] | 0 |
search-suggestions-system | EASY PROGRAM IN JAVA | easy-program-in-java-by-nidhibaratam2005-6pxo | Code | nidhibaratam2005 | NORMAL | 2025-01-02T05:23:41.810145+00:00 | 2025-01-02T05:23:41.810145+00:00 | 607 | false |
# Code
```java []
class Solution {
public List<List<String>> suggestedProducts(String[] products, String searchWord) {
Arrays.sort(products);
List<List<String>> ans=new ArrayList<List<String>>();
for (int i = 1; i <= searchWord.length(); i++) {
String prefix = searchWord.substr... | 5 | 0 | ['Array', 'String', 'Trie', 'Sorting', 'Java'] | 1 |
search-suggestions-system | Sort products and use `bisect_left` | sort-products-and-use-bisect_left-by-bur-hiot | Code\n\nclass Solution:\n def suggestedProducts(self, p: List[str], s: str) -> List[List[str]]:\n p.sort()\n ret = []\n for i in range(1 | burkh4rt | NORMAL | 2024-01-18T03:18:42.372937+00:00 | 2024-01-18T03:18:42.372956+00:00 | 464 | false | # Code\n```\nclass Solution:\n def suggestedProducts(self, p: List[str], s: str) -> List[List[str]]:\n p.sort()\n ret = []\n for i in range(1, len(s) + 1):\n j=bisect_left(p, s[:i])\n ret.append([x for x in p[j:j+3] if x.startswith(s[:i])])\n return ret\n``` | 5 | 0 | ['Python3'] | 0 |
search-suggestions-system | ✅ 90.51% Binary Search Unleashed | 9051-binary-search-unleashed-by-vanamsen-79c1 | Intuition\nThe problem revolves around finding product suggestions as we type each character of a search word. One of the immediate observations is that if the | vanAmsen | NORMAL | 2023-10-31T02:08:31.214698+00:00 | 2023-10-31T02:08:31.214720+00:00 | 1,267 | false | # **Intuition**\nThe problem revolves around finding product suggestions as we type each character of a search word. One of the immediate observations is that if the products list was sorted, our task of finding the lexicographically smallest products would become easier. Given a prefix from the search word, we would n... | 5 | 0 | ['Binary Search', 'Sorting', 'Python3'] | 3 |
search-suggestions-system | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-tjc2 | Using Sorting && Binary Search\n\n Time Complexity :- O(N * N * logM), M is the size of product array and N is the size of string\n\n Space Complexity :- O(N * | __KR_SHANU_IITG | NORMAL | 2022-08-27T06:25:10.264376+00:00 | 2022-08-27T06:25:10.264420+00:00 | 745 | false | * ***Using Sorting && Binary Search***\n\n* ***Time Complexity :- O(N * N * logM), M is the size of product array and N is the size of string***\n\n* ***Space Complexity :- O(N * N)***\n\n```\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n ... | 5 | 0 | ['Binary Search', 'C', 'Sorting', 'Binary Tree', 'C++'] | 2 |
search-suggestions-system | Sort & Simple Explaination || Brut Force No Trie || Beats 87% | sort-simple-explaination-brut-force-no-t-o9zv | 1 Firstly, we are going to simply sort the products array.\nNow all product are in lexicographically sorted order.\n\nHere we are going to use two pointer appro | mr_optimizer | NORMAL | 2022-07-04T06:55:30.420935+00:00 | 2022-07-04T06:55:30.420965+00:00 | 308 | false | 1 Firstly, we are going to simply sort the products array.\nNow all product are in lexicographically sorted order.\n\nHere we are going to use two pointer approach.\nlet, left = 0 and right is on last element of products.\nAnd i is searchWord;\nlet searchWord[i]==\'c\', then \n2. we check if product[left][i] != \'c\' t... | 5 | 0 | ['C', 'Binary Tree', 'C++'] | 0 |
search-suggestions-system | Search suggestion | Using Map |.Easy understanding | Idea | search-suggestion-using-map-easy-underst-u5qx | Hi,\n\nThis solution is for easy and simple understanding, idea behind this approach is to store the values in Hash map and retrive those records.\n\nHere are t | Surendaar | NORMAL | 2022-06-19T05:43:57.461918+00:00 | 2022-06-19T05:43:57.461950+00:00 | 706 | false | Hi,\n\nThis solution is for easy and simple understanding, idea behind this approach is to store the values in Hash map and retrive those records.\n\nHere are the steps:\n1. Read each of the products one by one e.g -> app, apple, apart\n2. For each element store the values in Map for each of the values and sort them us... | 5 | 0 | ['Java'] | 2 |
search-suggestions-system | SIMPLE C++ USING ONLY MAP | simple-c-using-only-map-by-lee_123_fan-es23 | vector> suggestedProducts(vector& products, string searchword) {\n unordered_map> m;\n \n sort(products.begin(),products.end());\n \ | lee_123_fan | NORMAL | 2022-06-19T00:55:40.790748+00:00 | 2022-06-19T00:55:40.790786+00:00 | 412 | false | vector<vector<string>> suggestedProducts(vector<string>& products, string searchword) {\n unordered_map<string,vector<string>> m;\n \n sort(products.begin(),products.end());\n \n for(auto x:products)\n {\n string s="";\n for(int i=0;i<x.size();i++)\n ... | 5 | 0 | [] | 0 |
search-suggestions-system | Java | Binary Search | Very Easy with Explanation | java-binary-search-very-easy-with-explan-5nzl | The idea here is to use prefix substrings from search word and use binary search to find if there\'re any words that start with the prefix substring in our prod | omars_leet | NORMAL | 2022-03-29T14:35:38.709331+00:00 | 2022-03-29T14:42:54.865874+00:00 | 352 | false | The idea here is to use prefix substrings from `search word` and use binary search to find if there\'re any words that start with the prefix substring in our products list.\n\nIf we didn\'t find any matching substring, since our products are sorted, we can take the next word that is closest to the prefix substring. (in... | 5 | 0 | ['Binary Tree', 'Java'] | 1 |
search-suggestions-system | Search Suggestions System | Simple Binary Search Solution | search-suggestions-system-simple-binary-qybz2 | Intuition\nSort the products and do binary search on prefix of products(Strings),we only need to consider 3 best matching strings, if for any string we found th | shivaye | NORMAL | 2021-05-31T07:14:47.335517+00:00 | 2021-05-31T07:17:17.660212+00:00 | 122 | false | **Intuition**\nSort the products and do binary search on prefix of products(Strings),we only need to consider 3 best matching strings, if for any string we found that the prefix is not matching then we need not to check for further strings.\n\n```\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts... | 5 | 5 | ['C'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.