Skip to content

My solutions to coding interview problems on Leetcode, Algoexpert, Codewars and other interview preparation websites

Notifications You must be signed in to change notification settings

deepaktalwardt/interview-prep-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Interview Preparation

My solutions to coding interview problems on LeetCode, AlgoExpert, Codewars, EPI book, Pramp, Codility and other interview preparation resources. I will be adding my solutions to this repository every day starting September 15, 2019.

Difficulty Levels solved

βšͺ Easy: 50
πŸ”΅ Medium: 96
πŸ”΄ Hard: 24
⚫ Very Hard: 5
⭐ Good to review

Total: 175

Day 0

Adding solutions to all problems I have already completed

LeetCode

  1. πŸ”΅ ⭐ 5-longest-palindromic-substring.cpp
  2. πŸ”΅ ⭐ 19-remove-nth-node-from-end-of-list.cpp
  3. βšͺ 21-merge-two-sorted-lists.cpp
  4. βšͺ ⭐ 101-symmetric-tree.cpp
  5. βšͺ 104-maximum-depth-of-binary-tree.cpp
  6. βšͺ 110-balanced-binary-tree.cpp
  7. βšͺ 118-pascals-triangle.cpp
  8. βšͺ ⭐ 206-reverse-linked-list.cpp
  9. βšͺ ⭐ 226-invert-binary-tree.cpp
  10. βšͺ ⭐ 572-subtree-of-another-tree.cpp
  11. βšͺ 617-merge-two-binary-trees.cpp
  12. βšͺ 917-reverse-only-letters.cpp

AlgoExpert

  1. βšͺ bubble-sort.cpp
  2. βšͺ caesar-cipher-encryptor.cpp
  3. πŸ”΅ ⭐ longest-palindromic-substring.cpp
  4. βšͺ palindrome-check.cpp
  5. πŸ”΅ remove-kth-node-from-end.cpp
  6. πŸ”΄ reverse-linked-list.cpp
  7. πŸ”΅ ⭐ smallest-difference.cpp
  8. βšͺ two-number-sum.cpp

Day 1

Focus for today: Heaps/Priority Queues

LeetCode

  1. πŸ”΅ ⭐ 347-top-k-frequent-elements.cpp
  2. πŸ”΅ 692-top-k-frequent-words.cpp

AlgoExpert

  1. πŸ”΅ ⭐ min-heap-construction.cpp

Day 2

Focus for today: Heaps/Priority Queues

LeetCode

  1. πŸ”΄ ⭐ 23-merge-k-sorted-lists.cpp Hint: No need to add entire lists to heaps at first!

AlgoExpert

  1. πŸ”΅ invert-binary-tree.cpp Hint: You can't invert right if you've already invert left.
  2. βšͺ binary-search.cpp Hint: Helper helps!

Day 3

Focus for today: Heaps/Priority Queues/Mock Interview Practice

LeetCode

  1. βšͺ 796-is-rotation.cpp Hint: Don't try anything fancy! Think about how strings wrap around.
  2. πŸ”΅ ⭐ 229-majority-element-ii.cpp Hint: How many elements can be in the solution if majority is defined by having floor(n/3) elements?

AlgoExpert

  1. πŸ”΄ ⭐ contiunous-median.cpp Hint: Remember to rebalance the heaps!

Day 4

Focus for today: Heaps/Priority Queues, Common LeetCode questions

LeetCode

  1. βšͺ ⭐ 1-two-sum.cpp Hint: Think about what data structure to use. Don't try regular iteration!
  2. πŸ”΅ ⭐ 2-add-two-numbers.cpp Hint: Recall elementary math! Also don't forget about the carry!

Day 5

Focus for today: Common LeetCode questions, Heaps/Priority Queues

LeetCode

  1. βšͺ 20-valid-parentheses.cpp Hint: Compare chars instead of strings!
  2. βšͺ 937-reorder-data-in-log-files.cpp Hint: find_first_of method can be used to find first space in a string!
  3. βšͺ 973-k-closest-points-to-origin.cpp Hint: Heap is your friend!

AlgoExpert

  1. πŸ”΅ ⭐ bst-traversal.cpp Hint: Don't append to the array, replace it!

Elements of Programming Interviews

  1. πŸ”΅ 10-4-k-closest-stars.cpp Hint: Don't load everything into memory, use interators to point from beginning to end of stars list.

Day 6

Focus for today: Pramp interview

Pramp

  1. πŸ”΅ ⭐ decode-variations.cpp Hint: Iterate backwards, don't actually create the variations.
  2. πŸ”΅ busiest-time-in-mall.cpp Hint: Time stamps can be repeated! What happens at the last one?.

Day 7

Focus for today: Heaps, Graphs

LeetCode

  1. πŸ”΅ ⭐ 215-kth-largest-element-in-array.cpp Hint: Use a heap, but see if you can find a way to NOT include all elements in a heap.

AlgoExpert

  1. βšͺ depth-first-search.cpp Hint: Use recursion!
  2. πŸ”΅ ⭐ has-single-cycle.cpp Hint: Make sure index is already corrected at the end of the for loop!
  3. πŸ”΅ breadth-first-search.cpp Hint: Iterate and think about what data structure to use.
  4. πŸ”΅ ⭐ river-sizes.cpp Hint: Use DFS/BFS as soon as you find a river. Keep track of already visited ones.

Day 8

Focus for today: Graphs

LeetCode

  1. πŸ”΅ 200-number-of-islands.cpp Hint: Recursive DFS is much faster!

Day 9

Focus for today: Graphs

AlgoExpert

  1. πŸ”΅ ⭐ youngest-common-ancestor.cpp Hint: Get to the same depth!
  2. πŸ”΄ ⭐ lowest-common-manager.cpp Hint: Don't forget about the edgecase where one of the reports could be the manager!

Day 10

Focus for today: Graphs

LeetCode

  1. βšͺ 661-image-smoother.cpp Hint: Dont' over complicate it.

AlgoExpert

  1. ⚫ ⭐ rectangle-mania.cpp Hint: What do diagonals tell you? Can a datastructure give you better lookup than the vector?

Day 11

Focus for today: Arrays and Strings

LeetCode

  1. πŸ”΅ 362-design-hit-counter.cpp Hint: What data structure helps you to remove older values easily?.

Pramp

  1. πŸ”΅ ⭐ getting-a-different-number.cpp Hint: There are 3 ways to do it! O(N) is possible but not intuitive.

Day 12

Practiced but did not have any answers completed.

Day 13

Focus for today: Arrays and Strings

LeetCode

  1. πŸ”΅ ⭐ 785-is-graph-bipartite.cpp Hint: Any neighbor of a node cannot have the same color as itself.
  2. πŸ”΅ 364-nested-list-weight-sum-ii.cpp Hint: Iterate through, add an integer as many times as there are levels below it.

Pramp

  1. πŸ”΄ word-count-engine.cpp Hint: You cannot do sorting and counting at the same time.

Day 14

Focus for today: Arrays and Strings

LeetCode

  1. βšͺ 268-missing-number.cpp Hint: What was gauss's formula? Use it!
  2. πŸ”΅ ⭐ 15-3sum.cpp Hint: Remember to skip the repeated ones!

AlgoExpert

  1. πŸ”΅ ⭐ three-number-sum.cpp Hint: Two loops is okay.
  2. πŸ”΄ ⭐ four-number-sum.cpp Hint: Can you divide this into a two sum problem with 2 loops? Only store the tuple of values AFTER you have visited the first.
  3. πŸ”΄ ⭐ subarray-sort.cpp Hint: Find the smallest and largest out of order numbers. Where will you place them now?.

Day 15

Focus for today: Arrays and Strings, Graphs

AlgoExpert

  1. πŸ”΄ ⭐ largest-range.cpp Hint: Store everything in a data structure, and search forwards and backwards. Mark numbers you've already seen before.

60a. πŸ”΄ ⭐ min-rewards.cpp (Naive) Hint: While going backwards, make sure to keep track of previous reward for that student! Choose the larger.

60b. πŸ”΄ min-rewards.cpp (Peaks and Valleys) Hint: Find valleys and iterate outwards incrementing rewards as you go. Don't forget to choose the larger between the previous and the new reward!

60c. πŸ”΄ min-rewards.cpp (Two sweep) Hint: Sweep once from either direction, increment rewards only on positive slope! Don't forget to choose the larger between the previous and the new reward!

LeetCode

  1. πŸ”΅ ⭐ 994-rotting-oranges.cpp Hint: Use a datastructure to store depth for each newly rotten orange.

  2. βšͺ ⭐ 121-best-time-to-buy-and-sell-stock.cpp Hint: Store the minimum so far and keep maximum difference at every time step.

  3. βšͺ 88-merge-sorted-array.cpp Hint: Do the merge step from mergesort from the back!.

  4. βšͺ 283-move-zeroes.cpp Hint: Use the fast/slow pointer approach! Keep track of where the last non-zero element was seen.

  5. πŸ”΅ ⭐ 11-container-with-most-water.cpp Hint: Traverse from both ends.

Day 16

Focus for today: Arrays, Pramp interview

AlgoExpert

  1. πŸ”΄ ⭐ zigzag-traverse.cpp Hint: Pay attention to the conditions when you need to NOT go diagonally. Keep track of the direction.

Day 17

Focus for today: Arrays

LeetCode

  1. πŸ”΅ 59-spiral-matrix-ii.cpp Hint: Keep track of beggining and ending indices of rows and columns as you rotate around the matrix. Increment or decrement as you finish any row or column.`
  2. πŸ”΅ 54-spiral-matrix.cpp Hint: Keep track of beggining and ending indices of rows and columns as you rotate around the matrix. Increment or decrement as you finish any row or column. Have you violated the constraints while inside the loop?`

Day 18

Focus for today: Arrays

LeetCode

  1. πŸ”΅ ⭐ 161-one-edit-distance.cpp Hint: Iterate over both and keep account of differences.

Day 19

Focus for today: Arrays

LeetCode

  1. πŸ”΅ 48-rotate-image.cpp Hint: Keep track of row and column limits and go around in a circle. Make the circle smaller once all are done.

Day 20

Skipped, other priorities for the day.

Day 21

Focus for today: Dynamic Programming

AlgoExpert

  1. πŸ”΅ ⭐ maximum-subset-sum-with-no-adjacent-elements.cpp Hint: Iterate looking backwards. The current max is the max of either the max at previous index, or sum of current index and the max and previous to previous index.

  2. πŸ”΅ ⭐ number-of-ways-to-make-change.cpp Hint: For d in denominations, check each amount 0-n and add ways possible.

  3. πŸ”΅ ⭐ min-number-of-coins-for-change.cpp Hint: Make a list from 0-n, and at each index find the min number of coins for change. Choose min of current value, and 1 + min ways to make change of the remainder after using a denomination

LeetCode

  1. βšͺ ⭐ 53-maximum-subarray.cpp Hint: Maximum subarray at i is max of current number or sum of previous max and current number.

Day 22

Focus for today: Dynamic Programming, Mock interview

LeetCode

  1. πŸ”΅ ⭐ 91-decode-ways.cpp Hint: Iterate backwards and count number of ways to decode if you combine two adjacent characters. Add up to index 0 and that's your answer.

  2. βšͺ 561-array-partition-i.cpp Hint: What does sorting tell you?

  3. βšͺ ⭐ 7-reverse-integer.cpp Hint: Remember that current digit comes from modulo operator. How do you check whether your current answer has overflowed, either in positive or negative directions?

Day 23

Focus for today: Dynamic Programming, Mock interview

LeetCode

  1. πŸ”΅ ⭐ 322-coin-change.cpp Hint: Make a list from 0-n, and at each index find the min number of coins for change. Choose min of current value, and 1 + min ways to make change of the remainder after using a denomination.

AlgoExpert

  1. πŸ”΅ levenshtein-distance.cpp Hint: Remember to consider empty spaces at the beginning of strings. Initialize the first row and column. If current character in str1 is not equal to that in str2, add 1 to min of surrounding three. Else, copy the diagonal value as if the new character did not exist.

Day 24

Focus for today: Graphs and review

AlgoExpert

  1. πŸ”΄ ⭐ topological-sort.cpp Hint: Do recursive DFS and add each node after all of its pre-requisites are already in the list. To deal with cycles, keep track of nodes that are currently in the DFS stack.

  2. πŸ”΅ ⭐ kadanes-algorithm.cpp Hint: Maximum subarray at i is max of current number or sum of previous max and current number.

LeetCode

  1. βšͺ 541-reverse-string-ii.cpp Hint: Swap from 0-k, then jump to index 2k.

  2. ⚫ ⭐ 1192-critical-connections-in-a-network.cpp Hint: (Tarjan's) Do DFS, and convert undirected edges to directed in the order of DFS. Keep track of node ids and lowest id traversable from a node. Bridge occurs when id of current node is less than lowest node that can be found by the neighbor.

  3. πŸ”΅ ⭐ 207-course-schedule.cpp Hint: Topological Sort. Keep track of cycles in pre-requisites by checking if the node you're currently checking is in the stack already. Remember to visit the node AFTER visiting all its neighbors.

Day 25

Focus for today: Coding challenge from a Company

Day 26

Skipped. Midterm at school.

Day 27

Focus for today: Dynamic Programming

AlgoExpert

  1. πŸ”΄ ⭐ max-sum-increasing-subsequence.cpp Hint: At i, iterate from 0 to i-1 and check what the max sum increasing subsequence up until that point is. To build array, keep track of the previous index.

  2. πŸ”΄ water-area.cpp Hint: At every index, find the left max pillar and the right max pillar, then calculating area at that level is easy.

LeetCode

  1. πŸ”΄ ⭐ 42-trapping-rain-water.cpp Hint: Extension of water-area.cpp Use only one array for holding the min if left max pillar and right max pillar.

Day 28

Focus for today: Dynamic Programming

  1. πŸ”΄ ⭐ knapsack-problem.cpp Hint: Use a 2D array tracking maxValue possible with given items and given capacity size. Current max value is comes from either using the previous max value, or adding the current value with the max value obtained from adding the remainder into the knapsack. Build resulting array by backtracking from max value.

Day 29

Skipped. Preparing for midterm.

Day 30

Skipped. Preparing for midterm.

Day 31

Focus for today: Dynamic Programming

AlgoExpert

  1. πŸ”΄ ⭐ longest-common-subsequence.cpp Hint: Create a 3D array to keep track of common subsequences between arrays ending at each index. If current characters match, use the diagonal value and append current character to it. Else, use the longer of top or left.

LeetCode

  1. βšͺ 70-climbing-stairs.cpp Hint: To get to the current step, you can either take a single 1-step from the previous one, or a single 2-step from the previous to previous one.

  2. βšͺ 746-min-cost-climbing-stairs.cpp Hint: Cost of climbing to current step is sum of cost of being on this step and minimum of either the cost of coming from previous step or previous to previous step.

Day 32

Focus for today: Dynamic Programming

AlgoExpert

  1. ⚫ ⭐ max-profit-with-k-transactions.cpp Hint: Come back to this problem! Max profit at current transaction and day is obtained by either selling the stock or by not selling the stock and keeping the previous maximum. Keep track of max profit obtained thus far for each transaction.

Pramp

  1. πŸ”΅ matrix-spiral-copy.cpp Hint: Keep track of left, right, top and bottom boundaries and increment/decrement them as you go along.

Day 33

Focus for today: Dynamic Programming and Graphs

LeetCode

  1. πŸ”΅ ⭐ 1042-flower-planting-with-no-adjacent.cpp Hint: Do not overthink this one! Look at neighbors and assign yourself the first color available.

  2. πŸ”΅ 1079-letter-tile-possibilities.cpp Hint: First create a map with character counts. Then do recursive DFS and count by removing one character at a time and one length at a time.

Day 34

Focus for today: Common Google problems

LeetCode

  1. πŸ”΅ 394-decode-string.cpp Hint: Use two stacks, one for string and the other for numbers. Do the necessary things when you encounter a number, either of the brackets or just a character.

  2. πŸ”΅ ⭐ 139-word-break.cpp Hint: Think of it in terms of segmentation. A string can be segmented into words from dictionary if a part of it can be segmented, and the remaining directly exists in the dictionary.

Day 35

Focus for today: Common Google problems

LeetCode

  1. πŸ”΅ ⭐ 743-network-delay-time.cpp Hint: Remember to check if the delay at any node can be updated to a smaller one!

  2. βšͺ 551-student-attendance-record-i.cpp Hint: Don't need one.

  3. βšͺ 359-logger-rate-limiter.cpp Hint: Just what it sounds like.

  4. πŸ”΅ 1055-shortest-way-to-form-string.cpp Hint: Use a pointer each for both strings, compare characters and move accordingly. Keep track of how many characters you skip, if you skipped all of source string, return -1.

Day 36

Focus for today: Common Google problems

LeetCode

  1. πŸ”΅ ⭐ 253-meeting-rooms-ii.cpp Hint: How can I use a min-heap for this? Use ending times in the heap to check what the earliest end time is.

  2. πŸ”΅ ⭐ 221-maximal-square.cpp Hint: Brute force: When you find one, assume square starts at top-left, keep expanding diagonally and record how many levels are valid (i.e., don't have a 0). Dynamic Programming: For the current index to be part of a square, which previous conditions need to be true?

  3. πŸ”΅ ⭐ 56-merge-intervals.cpp Hint: Be careful in selecting what to compare the next index in the array with!

  4. πŸ”΅ ⭐ 939-minimum-area-rectangle.cpp Hint: Brute force: Create a map from string to Point and for each point, search for points in top-right and attempt to create a rectangle. If it forms, calculate its area.

  5. πŸ”΅ 1007-minimum-domino-rotations-for-equal-row.cpp Hint: Choose first values and iterate through the lists, first checking how many rotations would be needed for making row A equal to A[0] and then row B equal to A[0]. If not possible, try with B[0].

  6. βšͺ 867-transpose-matrix.cpp Hint: Copy from [r][c] to [c][r].

AlgoExpert

  1. πŸ”΅ ⭐ powerset.cpp Hint: Iteratively append the current element to all previously added subsets in the result.

Day 37

Focus for today: Common Google problems

LeetCode

  1. βšͺ 299-bulls-and-cows.cpp Hint: You can do it without O(N) additional space! Can you mark the already chosen ones?

Day 38

Skipped, preparing for project assignment.

Day 39

Skipped, preparing for project assignment.

Day 40

Focus for today: Mock interview

  1. πŸ”΅ 281-zigzag-iterator.cpp Hint: You don't need two pointers.

Day 41

Focus for today: Common questions

AlgoExpert

  1. βšͺ ⭐ find-largest-three-numbers.cpp Hint: Use a min-heap to keep track of largest three.

  2. πŸ”΅ search-in-sorted-matrix.cpp Hint: At each iteration you can ignore either a row or column if it is not equal to target.

Day 42

Skipped: Attending CalHacks

Day 43

Skipped: Attending CalHacks

Day 44

Skipped: Attending CalHacks

Day 45

LeetCode

  1. πŸ”΅ ⭐ 240-search-a-2d-matrix-ii.cpp Hint: Which corner do you want to start at? A corner that tells you more about which row or column you can ignore.

  2. πŸ”΅ 74-search-a-2d-matrix.cpp Hint: Find the correct row to search!

  3. πŸ”΅ 531-lonely-pixel-i.cpp Hint: Two passes are fine!

  4. βšͺ 141-linked-list-cycle.cpp Hint: Make two pointers race.

  5. βšͺ 198-house-robber.cpp Hint: What is the max profit at second position?

  6. πŸ”΄ 124-binary-tree-maximum-path-sum.cpp Hint: Keep a global max.

AlgoExpert

  1. πŸ”΅ balanced-brackets.cpp Hint: What are the cases when brackets are not balanced?

Day 46

LeetCode

  1. πŸ”΅ ⭐ 79-word-search.cpp Hint: (1) Iterative: What happens if you go down the wrong path and need to reset back to the valid path? Backtracking! (2) Recursive: Don't need to worry about backtracking. How would you keep track of the path you're on?

  2. πŸ”΄ 308-range-sum-query-2d-mutable.cpp Hint: There is a dynamic programming way to do later.

  3. βšͺ 26-remove-duplicates-from-sorted-array.cpp Hint: Use two pointers and keep the slow pointer as the end of the array you return.

Day 47

Pramp

  1. πŸ”΅ sales-path.cpp Hint: Same as finding min cost path.

LeetCode

  1. πŸ”΅ 105-construct-binary-tree-from-preorder-and-inorder-traversal.cpp Hint: Identify which nodes belong to the right and left subtree in both traversals.

Day 48

Skipped, working on assignment.

Day 49

Pramp

  1. πŸ”΅ array-of-array-products.cpp Hint: Forwards and Backwards pass.

LeetCode

  1. πŸ”΅ ⭐ 238-product-of-array-except-self.cpp Hint: Forwards and backwards pass.

AlgoExpert

  1. πŸ”΄ ⭐ find-loop.cpp Hint: Do the math! Find the relation between where you are and where the intersection is. Then move one of the pointers to the head and traverse both at the same speed.

  2. πŸ”΄ shifted-binary-search.cpp Hint: Add an extra condition to choose where to perform binary search.

Day 50

AlgoExpert

  1. πŸ”΄ ⭐ min-number-of-jumps.cpp Hint: Keep track of maxReach and steps available to take with the given number of jumps.

  2. πŸ”΄ ⭐ longest-substring-without-duplication.cpp Hint: Keep last seen index of each character in an unordered_map and update the startIdx when the current character already exists in the map.

Day 51

Skipped, midterm at school.

Day 52

LeetCode

  1. πŸ”΅ ⭐ 3-longest-substring-without-repeating-characters.cpp Hint: Check for maxLen at every index, and update the startIdx every time you find a character that already exists in the map.

  2. πŸ”΅ 289-game-of-life.cpp Hint: How can you encode the transitions between states in place?

  3. πŸ”΅ ⭐ 33-search-in-rotated-sorted-array.cpp Hint: If left array is not sorted, right must be sorted, and vice versa!

Day 53

EPI

  1. πŸ”΅ string-match.cpp Hint: How can you use hashing?

LeetCode

  1. πŸ”΅ ⭐ 81-search-in-rotated-sorted-array-ii.cpp Hint: Think about what you should do when left index and middle index are the same value.

Day 54

EPI

  1. πŸ”΅ ⭐ rook_attack.cpp Hint: Two passes are fine.

LeetCode

  1. πŸ”΅ ⭐ 841-keys-and-rooms.cpp Hint: Can you find a path to all rooms?

  2. πŸ”΅ 560-subarray-sum-equals-k.cpp Hint: Keep track of sums from 0 to i.

Day 55

AlgoExpert

  1. πŸ”΄ ⭐ max-path-sum-in-binary-tree.cpp Hint: Need to keep track of multiple things at every recursive call.

Day 56

LeetCode

  1. βšͺ 953-verifying-an-alien-dictionary.cpp Hint: Store the order in a map.

  2. βšͺ 997-find-the-town-judge.cpp Hint: Find incoming and outgoing degrees.

  3. πŸ”΅ ⭐ 277-find-the-celebrity.cpp Hint: Find a candidate and verify, else cannot be found.

Day 57

LeetCode

  1. πŸ”΅ ⭐ 261-graph-valid-tree.cpp Hint: Use union find and check for cycles when adding an edge.

Day 58

AlgoExpert

  1. βšͺ branch-sums.cpp Hint: Read the definition of branch sum carefully.

  2. πŸ”΅ group-anagrams.cpp Hint: Sort each word and then use a hashmap to add them to the same vector.

Day 59

AlgoExpert

  1. πŸ”΅ ⭐ permutations.cpp Hint: (1: Better) With the first number fixed, create permutations for all other numbers by swapping them. Once you're at the end of the list, you have found one permutation. (2: Worse) Take an element out of the array, create permutations of all others, and append element to each permutation.

LeetCode

  1. πŸ”΅ ⭐ 22-generate-parentheses.cpp Hint: Recursively add either '(' or ')' depending on which one is available. Add to the result once the length of current permutation hits 2*n.

  2. βšͺ 14-longest-common-prefix.cpp Hint: Compare until not equal.

Day 60

LeetCode

  1. πŸ”΅ 49-group-anagrams.cpp Hint: Sort each word and use a hashmap to add them to the same vector.

  2. πŸ”΅ ⭐ 17-letter-combinations-of-a-phone-number.cpp Hint: Iterative + Recursive: Iterate over all possible next characters and recursively build up the solutions. Once you reach the end of the digits string, you have found one combination.

Day 61

LeetCode

  1. βšͺ 840-magic-squares-in-grid.cpp Hint: What should sum of each row and column be equal to?

  2. βšͺ 929-unique-email-addresses.cpp

Day 62

AlgoExpert

  1. βšͺ product-sum.cpp Hint: How do you handle the level?

  2. βšͺ find-closest-in-bst.cpp Hint: Can you do it both recursively and iteratively?

LeetCode

  1. πŸ”΅ ⭐ 159-longest-substring-with-two-distinct-chars.cpp Hint: Find a way to not have to clear the entire map when map size becomes greater than 2.

Day 63

Pramp

  1. πŸ”΅ find-the-duplicates.cpp Hint: Make use of the sorted nature.

AlgoExpert

  1. πŸ”΅ move-element-to-end.cpp Hint: Use two pointers.

LeetCode

  1. πŸ”΅ ⭐ 98-validate-binary-search-tree.cpp Hint: What are the limits for each BST nodes' values?

Day 64

AlgoExpert

  1. πŸ”΅ ⭐ validate-bst.cpp Hint: Make sure you keep track of the limits of the BST nodes' values.

LeetCode

  1. πŸ”΅ 681-next-closest-time.cpp Hint: Simulate time forwarding.
  2. πŸ”΅ ⭐ 904-fruit-into-baskets.cpp Hint: Similar to longest substring with 2 distinct elements.

Day 65

LeetCode

  1. πŸ”΅ ⭐ 399-evaluate-division.cpp Hint: What datastructure can be best used to describe this problem?

AlgoExpert

  1. ⚫ ⭐ knuth-morris-pratt-algorithm.cpp Hint: Build the pattern for the substring first, then start comparing. During comparison, instead of going back to the front of the string at failure, go to the previously found pattern that matches.

  2. πŸ”΄ ⭐ quick-sort.cpp Hint: Choose a pivot and move smaller elements to its left and larger to its right.

Day 66

LeetCode

  1. πŸ”΅ ⭐ 286-walls-and-gates.cpp Hint: Multi-start BFS.
  2. βšͺ 100-same-tree.cpp
  3. πŸ”΅ ⭐ 323-number-of-connected-components-in-undirected-graph.cpp Hint: Use Union-Find, and make sure to combine parents of parents in a component as well.

Day 67

LeetCode

  1. πŸ”΅ ⭐ 1102-path-with-maximum-minimum-value.cpp Hint: Can a path finding algorithm work?
  2. πŸ”΅ ⭐ 1135-connecting-cities-with-minimum-cost.cpp Hint: Use Union-Find.
  3. πŸ”΅ ⭐ 983-minimum-cost-for-tickets.cpp Hint: What should you iterate over?
  4. ⚫ ⭐ 297-serialize-and-deserialize-binary-tree.cpp Hint: What order traversal would you use to serialize?

Day 68

AlgoExpert

  1. πŸ”΄ ⭐ palindrome-partitioning-min-cuts.cpp Hint: (1): For all substrings check if it is a palindrome. Then iterate over the string to develop dp logic.

LeetCode

  1. πŸ”΅ ⭐ 46-permutations.cpp Hint: For each element in the array, swap it to the front and permute the rest. Then prepend it back.
  2. πŸ”΄ 132-palindrome-partitioning.cpp Hint: For all substrings check if it is a palindrome. Then iterate over the string to develop dp logic.

Day 69

LeetCode

  1. βšͺ ⭐ 136-single-number.cpp Hint: Can you just use math? Can you go even lower to bit manipulation?

About

My solutions to coding interview problems on Leetcode, Algoexpert, Codewars and other interview preparation websites

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages