Word Search 1 - Find if word exists

Problem Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. Example Example 1: $$ \begin{bmatrix} \color{red} A & \color{red} B & \color{red} C & E \\ S & F & \color{red} C & S \\ A & \color{red} D & \color{red} E & E \end{bmatrix} $$ ...

Longest Substring Without Repeating Characters Problem

Problem Given a string, find the length of the longest substring without repeating characters. Examples Example 1: Input: s = "aababcbb" Output: 3 Explanation: The longest substring without repeating characters is "abc". Example 2: Input: s = "cccc" Output: 1 Explanation: The longest substring without repeating characters is "c". ...

Top K Frequent Words Problem

Problem Given a document (or stream) of words. Find the top k most frequent words in the document (or stream). OR Given an array of strings words and an integer k, return the k most frequent strings. Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order. Examples Example 1: Input: words = ["i","love","leetcode","i","love","coding"], k = 2 Output: ["i","love"] Explanation: "i" and "love" are the two most frequent words. Note that "i" comes before "love" due to a lower alphabetical order. ...

H-Index 2 Problem

This is a follow up on H-Index Problem. What if the citations array is sorted in ascending order? Could you optimize your algorithm? Problem Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in an ascending order, return compute the researcher’s h-index. According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each. ...

Delete non-tail Node in linked list, Given only access to that Node

Problem Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not a tail node in the list. Examples Example 1: graph LR; 4 --> 5 --> 1 --> 9 style 5 fill:#FF9933 ...

H-Index Problem

Problem Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return compute the researcher’s h-index. According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each. If there are several possible values for h, the maximum one is taken as the h-index. ...

Design Add and Search Words Data Structure Problem

Problem Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: WordDictionary() Initializes the object. void addWord(word) Adds word to the data structure, it can be matched later. bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots '.' where dots can be matched with any letter. Examples Example 1: ...

Path with Maximum Probability Problem

Problem You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing that edge succProb[i]. Given two nodes start and end, find the path with the maximum probability of success to go from start to end and return its success probability. ...

Find the City With the Smallest Number of Neighbors at a Threshold Distance Problem

Problem There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer distanceThreshold. Return the city with the smallest number of cities that are reachable through some path and whose distance is at most distanceThreshold, If there are multiple such cities, return the city with the greatest number. ...

Average Waiting Time Problem

Problem There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]: arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order. timei is the time needed to prepare the order of the ith customer. When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy