Grind75 Flashcards

(68 cards)

1
A

Use a hash map to store the difference of the target and the current element as the key and the index as the value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Best Time To Buy And Sell Stock,https://leetcode.com/problems/best-time-to-buy-and-sell-stock

A

Keep track of the minimum price and maximum profit while iterating through the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Majority Element,https://leetcode.com/problems/majority-element

A

Use Boyer-Moore Voting Algorithm to find the majority element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Contains Duplicate,https://leetcode.com/problems/contains-duplicate

A

Use a set to check for duplicates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Insert Interval,https://leetcode.com/problems/insert-interval

A

Merge intervals while iterating through the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

3Sum,https://leetcode.com/problems/3sum

A

Sort the array and use three pointers to find the triplets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Product Of Array Except Self,https://leetcode.com/problems/product-of-array-except-self

A

Use two arrays to store the product of all elements to the left and right of each element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Combination Sum,https://leetcode.com/problems/combination-sum

A

Use backtracking to find all possible combinations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Merge Intervals,https://leetcode.com/problems/merge-intervals

A

Sort intervals by starting point and merge overlapping intervals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Sort Colors,https://leetcode.com/problems/sort-colors

A

Use the Dutch National Flag algorithm to sort the colors in one pass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Container With Most Water,https://leetcode.com/problems/container-with-most-water

A

Use two pointers to find the maximum area.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Invert Binary Tree,https://leetcode.com/problems/invert-binary-tree

A

Use a recursive function to swap the left and right children of each node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Balanced Binary Tree,https://leetcode.com/problems/balanced-binary-tree

A

Check if the difference in heights of the left and right subtrees is no more than one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Diameter of Binary Tree,https://leetcode.com/problems/diameter-of-binary-tree

A

Use a recursive function to find the maximum depth of the left and right subtrees.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Maximum Depth of Binary Tree,https://leetcode.com/problems/maximum-depth-of-binary-tree

A

Use a recursive function to find the maximum depth.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Binary Tree Level Order Traversal,https://leetcode.com/problems/binary-tree-level-order-traversal

A

Use a queue to traverse the tree level by level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Lowest Common Ancestor of a Binary Tree,https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree

A

Use a recursive function to find the lowest common ancestor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Binary Tree Right Side View,https://leetcode.com/problems/binary-tree-right-side-view

A

Use a queue to traverse the tree level by level and add the rightmost node of each level to the result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Construct Binary Tree from Preorder and Inorder Traversal,https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal

A

Use a recursive function to build the tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Serialize and Deserialize Binary Tree,https://leetcode.com/problems/serialize-and-deserialize-binary-tree

A

Use a queue to traverse the tree and serialize/deserialize it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Valid Palindrome,https://leetcode.com/problems/valid-palindrome

A

Use two pointers to check if the string is a palindrome.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Valid Anagram,https://leetcode.com/problems/valid-anagram

A

Use a hash map to count the frequency of each character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Longest Palindrome,https://leetcode.com/problems/longest-palindromic-substring

A

Use dynamic programming to find the longest palindromic substring.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Longest Substring Without Repeating Characters,https://leetcode.com/problems/longest-substring-without-repeating-characters

A

Use a sliding window to find the longest substring.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
String to Integer (atoi),https://leetcode.com/problems/string-to-integer-atoi
Handle whitespaces, signs, and overflow while converting the string to an integer.
26
Longest Palindromic Substring,https://leetcode.com/problems/longest-palindromic-substring
Use dynamic programming to find the longest palindromic substring.
27
Find All Anagrams in a String,https://leetcode.com/problems/find-all-anagrams-in-a-string
Use a sliding window and a hash map to find all anagrams.
28
Minimum Window Substring,https://leetcode.com/problems/minimum-window-substring
Use a sliding window and a hash map to find the minimum window substring.
29
Flood Fill,https://leetcode.com/problems/flood-fill
Use a queue or recursive function to perform the flood fill.
30
01 Matrix,https://leetcode.com/problems/01-matrix
Use a queue to perform a breadth-first search from all zero cells.
31
Clone Graph,https://leetcode.com/problems/clone-graph
Use a depth-first search to clone the graph.
32
Course Schedule,https://leetcode.com/problems/course-schedule
Use a depth-first search to detect cycles in the graph.
33
Number of Islands,https://leetcode.com/problems/number-of-islands
Use a depth-first search to count the number of islands.
34
Rotting Oranges,https://leetcode.com/problems/rotting-oranges
Use a queue to perform a breadth-first search from all rotten oranges.
35
Accounts Merge,https://leetcode.com/problems/accounts-merge
Use a union-find data structure to merge the accounts.
36
Word Search,https://leetcode.com/problems/word-search
Use a depth-first search to find the word in the grid.
37
Minimum Height Trees,https://leetcode.com/problems/minimum-height-trees
Use a breadth-first search to find the minimum height trees.
38
Word Ladder,https://leetcode.com/problems/word-ladder
Use a breadth-first search to find the shortest transformation sequence.
39
Valid Parentheses,https://leetcode.com/problems/valid-parentheses
Use a stack to check if the parentheses are valid.
40
Implement Queue using Stacks,https://leetcode.com/problems/implement-queue-using-stacks
Use two stacks to implement a queue.
41
Evaluate Reverse Polish Notation,https://leetcode.com/problems/evaluate-reverse-polish-notation
Use a stack to evaluate the reverse Polish notation.
42
Min Stack,https://leetcode.com/problems/min-stack
Use two stacks to implement a min stack.
43
Trapping Rain Water,https://leetcode.com/problems/trapping-rain-water
Use two pointers to find the amount of trapped rainwater.
44
Basic Calculator,https://leetcode.com/problems/basic-calculator
Use a stack to evaluate the expression.
45
Largest Rectangle in Histogram,https://leetcode.com/problems/largest-rectangle-in-histogram
Use a stack to find the largest rectangle.
46
Merge Two Sorted Lists,https://leetcode.com/problems/merge-two-sorted-lists
Use two pointers to merge the lists.
47
Linked List Cycle,https://leetcode.com/problems/linked-list-cycle
Use two pointers to detect a cycle in the linked list.
48
Reverse Linked List,https://leetcode.com/problems/reverse-linked-list
Use a recursive or iterative function to reverse the linked list.
49
Middle of the Linked List,https://leetcode.com/problems/middle-of-the-linked-list
Use two pointers to find the middle of the linked list.
50
LRU Cache,https://leetcode.com/problems/lru-cache
Use a hash map and a doubly linked list to implement the LRU cache.
51
Binary Search,https://leetcode.com/problems/binary-search
Use binary search to find the target element.
52
First Bad Version,https://leetcode.com/problems/first-bad-version
Use binary search to find the first bad version.
53
Search in Rotated Sorted Array,https://leetcode.com/problems/search-in-rotated-sorted-array
Use binary search to find the target element.
54
Time Based Key-Value Store,https://leetcode.com/problems/time-based-key-value-store
Use a hash map and a list to store the key-value pairs.
55
Maximum Profit in Job Scheduling,https://leetcode.com/problems/maximum-profit-in-job-scheduling
Use dynamic programming to find the maximum profit.
56
Lowest Common Ancestor of a Binary Search Tree,https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree
Use a recursive function to find the lowest common ancestor.
57
Validate Binary Search Tree,https://leetcode.com/problems/validate-binary-search-tree
Use a recursive function to validate the binary search tree.
58
Kth Smallest Element in a BST,https://leetcode.com/problems/kth-smallest-element-in-a-bst
Use an inorder traversal to find the kth smallest element.
59
Climbing Stairs,https://leetcode.com/problems/climbing-stairs
Use dynamic programming to find the number of ways to climb the stairs.
60
Maximum Subarray,https://leetcode.com/problems/maximum-subarray
Use dynamic programming to find the maximum subarray.
61
Coin Change,https://leetcode.com/problems/coin-change
Use dynamic programming to find the minimum number of coins.
62
Partition Equal Subset Sum,https://leetcode.com/problems/partition-equal-subset-sum
Use dynamic programming to partition the array.
63
Unique Paths,https://leetcode.com/problems/unique-paths
Use dynamic programming to find the number of unique paths.
64
Ransom Note,https://leetcode.com/problems/ransom-note
Use a hash map to count the frequency of each character.
65
Add Binary,https://leetcode.com/problems/add-binary
Use a loop to add the binary numbers.
66
Spiral Matrix,https://leetcode.com/problems/spiral-matrix
Use four pointers to traverse the matrix in a spiral order.
67
K Closest Points to Origin,https://leetcode.com/problems/k-closest-points-to-origin
Use a priority queue to find the k closest points.
68
Task Scheduler,https://leetcode.com/problems/task-scheduler
Use a priority queue to schedule the tasks