Haroon Ullah

Haroon Ullah is a member of the Secretary of State’s Policy Planning Staff, where his portfolios include countering violent extremism and public diplomacy. Previously, he served as director of the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




LeetCode Grind 75

Easy·15 mins·Array

Used a HashMap to keep track of the compliments adding to target and return their indexes.

Easy·20 mins·Stack

Used a Stack to ensure brackets are matched correctly. If the stack isn’t empty there are unmatched brackets.

Easy·20 mins·Linked List

Create a prehead and add nodes iteratively. Append whichever node isn’t None to the end of the merged list.

Easy·20 mins·Array

The first price is used as the min then max profits and min starting prices are calculated iteratively, since stocks can only be sold the day after they are bought in this senario.

Easy·15 mins·String

Used double pointers to iteratively check if left most and right most characters are equal skipping non alphanumeric characters.

Easy·15 mins·Binary Tree

Breath First approach queuing and switching nodes as needed. Works even if the root node is Null.

Easy·15 mins·String

Track character frequency in each string and ensure they’re equal.

Easy·15 mins·Binary Search

Easy·20 mins·Graph

Breadth First Search using deque for the Flood Fill implementation.

Easy·20 mins·Binary Search Tree

Build a path to each node from the root using DFS. Then iterate through common elements and return the one with the greatest depth.

Easy·15 mins·Binary Tree

This solution recursively check if the depth of each subtree is balanced given a node (eg. the depth of the two subtrees of every node never differs by more than one). For each node at n depth, height will be called recursively n times.

Easy·20 mins·Linked List

Use the fast and slow pointer method to check for a cycle.

Easy·20 mins·Stack

Create an outstack and an instack. Push to the instack. Reverse the instack using the outstack and pop the last item (ie the front of the queue) when a value is popped or peeked from the Queue. This processes is only repeated when the outstack is empty.

Easy·20 mins·Binary Search

This problem requires mid = start + (end-start) // 2 to prevent overflow due to the constraints.

Easy·15 mins·Hash Table

The magazine can have an excess of unused letters. Could also just use Counter.

Easy·20 mins·Dynamic Programming

Iterate through the array, starting at dp[2], and set dp[i] as the sum of dp[i-1] and dp[i-2] to take 1 step or 2 steps to reach step N.

Easy·20 mins·String

Use a HashSet to count the unpaired numbers. Return the number of paired numbers plus 1 if there’s an unpaired number that can be used in the palindrome.

Easy·20 mins·Linked List

Iterate through the link list storing next and previous reversing the next to previous at each iteration. Return previous since current should be set to None.

Easy·20 mins·Array

Keep frequency of nums and when one count exceeds half the length of the array return it.

Easy·15 mins·Binary

Easy·30 mins·Binary Tree

The tricky part is they’re asking for the length of the longest path between any two nodes in a tree. Not just the max depth.

Easy·20 mins·Linked List

Since the fast pointer is advancing twice as fast the slow pointer will always end in the middle.

Easy·15 mins·Binary Tree

Just a straight Depth First Search.

Easy·15 mins·Array

Hash Map to track frequency.

Medium·20 mins·Dynamic Programming

Medium·25 mins·Array

Insert the new interval at the correct index. Then overlapping ranges are fixed and removed.

Medium·30 mins·Graph

Medium·30 mins·Heap

Medium·30 mins·String

Medium·30 mins·Array

Using the two pointer method we loop iterate through all sorted values. If the triplet adds to zero we can add it to the results. Triplets are sorted and added to a set to prevent duplicates.

Medium·20 mins·Binary Tree

Medium·25 mins·Graph

Using DFS a clone is created for each node in the graph and a hashmap is used to keep track of previous visited nodes.

Medium·30 mins·Stack

Medium·30 mins·Graph

Medium·35 mins·Trie

Medium·25 mins·Dynamic Programming

Create a dynamic programming table setting the minimum number to arrive at each amount up to the target.

Medium·30 mins·Array

The prefix and suffix products are calculated for each position excluding the number then multiplied together for the answer. The problem asks not to use division and solve in O(N) time.

Medium·20 mins·Stack

Medium·20 mins·Binary Search Tree

Medium·25 mins·Graph

Medium·30 mins·Graph

Medium·30 mins·Binary Search

Medium·30 mins·Array

Medium·30 mins·Recursion

Using DFS each possible permutation is created recursively with the first position being created iteratively.

Medium·30 mins·Array

First the intervals are sorted by start. Next they are iterated through and appended to an answer array. If the end of the previous interval overlaps the start of the current they are merged with the previous start and the largest end.

Medium·25 mins·Binary Tree

Same as the solution for #10.

Medium·35 mins·Binary Search

Medium·30 mins·Graph

Medium·25 mins·Array

Medium·30 mins·Trie

Iterate through the input string and for each index, check if the substring segmented is a word in the dictionary. Then return dp[n] where N is the length of the input string to see if the entire string can be segmented.

Medium·30 mins·Dynamic Programming

Medium·25 mins·String

Using a stack we read valid characters from the string and break when a non numeric character is encountered. Then the total is calculated by popping numbers from the stack and multiplying by its base 10 position.

Medium·25 mins·Matrix

Medium·30 mins·Recursion

This solution generates all subsets of the nums using a backtracking algorithm.

Medium·20 mins·Binary Tree

Medium·25 mins·String

Iterate through center positions checking for the longest substring. The second I+1 called is used to check for a double character center.

Medium·20 mins·Dynamic Programming

Medium·25 mins·Binary Tree

Medium·35 mins·Array

Medium·30 mins·Recursion

Medium·30 mins·Graph

Medium·30 mins·String

Medium·30 mins·Graph

Medium·35 mins·Heap

Medium·30 mins·Linked List

Medium·25 mins·Binary Search Tree

Hard·30 mins·String

Hard·40 mins·Binary Tree

Hard·35 mins·Stack

Hard·30 mins·Heap

Hard·45 mins·Graph

Hard·40 mins·Stack

Hard·45 mins·Binary Search

Hard·30 mins·Heap

Hard·35 mins·Stack

Add a comment

Related posts:

Inclusive Playgrounds Are a Good Idea for All

Inclusive playgrounds ensure that all children can play together regardless of ability — and parents, grandparents and caregivers can play, too. Kylie, Aidan’s older sister, also waved from the top…

WHY ARE SMALL BUSINESSES BUILDING MOBILE APPS? AND ARE THEY IMPORTANT?

With the increase in total internet usage across all devices, Android OS has crossed Microsoft Windows as the leading OS globally. This win of Android deeply reflects on the progress made in the…

UX Research Basics

This simple checklist from Usability.gov contains the list of most popular research methods. Includes recommendations when to use a specific method during every phase of the user-centred design…