codeplayjourney
codeplayjourney
  • Видео 108
  • Просмотров 562
Leetcode 1717 - Maximum Score From Removing Substrings [12/7/24]
Time Taken: ~15 mins
Tag: LeetCode Medium
Concept: Stack, Greedy
High-level ideas:
- Remove substring greedily from higher priority substring to lower priority substring.
- Use stack for matching substring. Stack simulates the state of current string.
- To match “ba”: current character == ‘a’ and top of stack == ‘b’
- To match “ab”: current character == ‘b’ and top of stack == ‘a’
- Case 1: Match found - pop top character from stack
- Case 2: Match not found - add current character to top of stack
- Iterate through string s once to match higher priority string. Add score for each match to “ans”.
- Afterwards, iterate through the remaining string to match lower priority string. Add score for eac...
Просмотров: 4

Видео

Leetcode 1190 - Reverse Substrings Between Each Pair of Parentheses [11/7/24]
Просмотров 53 месяца назад
Time Taken: ~15 mins Tag: LeetCode Medium Concept: Simulation, Stack High-level ideas: - Keep state using stack. - Iterate through s: - If current character ‘)’, reverse string contained between current character and the latest ‘(‘, which can be obtained easily from stack - Else, add to stack - Final answer is obtained by reversing the stack. - Top of stack at end of ans string - Vice versa
Leetcode 1598 - Crawler Log Folder [10/7/24]
Просмотров 23 месяца назад
Time Taken: ~5 mins Tag: LeetCode Easy Concept: Simulation High-level ideas: - We keep track of “count” variable that represents number of steps from main folder. - Iterate through vector “logs”. Each string in “logs” represent the action done, in sequential order. - Case 1: “../“ - This action moves to parent folder of current folder - 1 step closer to main folder (decrement “count”) - Case 2:...
Leetcode 1701 - Average Waiting Time [9/7/24]
Просмотров 53 месяца назад
Time Taken: ~15 mins Tag: LeetCode Medium Concept: Simulation High-level ideas: - Traverse through customers array in order: - For current customer, calculate the waiting time, which is addition of: - Preparation time for current customer: - Second value - Waiting time before current customer is served: - If “currTime” is less than or equal “custArrivalTime” (first value), waiting time is 0 - E...
Leetcode 1823 - Find the Winner of the Circular Game [8/7/24]
Просмотров 33 месяца назад
Time Taken: ~10 mins Tag: LeetCode Medium Concept: Simulation, Queue High-level ideas: - Simulate the circle using queue data structure (Pop from front and push to back of queue) - Initialise queue by pushing everyone into queue. - For each iteration of while loop, 1 person is eliminated. (k - 1 people are popped from front and pushed to back of queue. kth person is eliminated.) - Exit while lo...
Leetcode 1518 - Water Bottles [7/7/24]
Просмотров 23 месяца назад
Time Taken: ~5 mins Tag: LeetCode Easy Concept: Simulation Basic ideas: - “numDrink” to keep track of number of bottles drank. Initialised to “numBottles” - Enter while loop and keep exchanging empty bottles if valid (“numBottles” greater than or equal to “numExchange”) - Calculate “numFullBottles” that can be exchanged and add to “numDrink” counter - Update“numBottles”, which is number of empt...
Leetcode 2582 - Pass the Pillow [6/7/24]
Просмотров 43 месяца назад
Time Taken: ~5 mins Tag: LeetCode Easy High-level ideas: - Find the number of effective passes from the first person in the forward direction. - Find if the last pass is in the forward or backward direction and calculate accordingly. - Forward direction: Count from first person forward - Backward direction: Count from last person backward
Leetcode 2058 - Find the Minimum and Maximum Number of Nodes Between Critical Points [5/7/24]
Просмотров 63 месяца назад
Time Taken: ~20 mins Tag: LeetCode Medium Concept: Linked List High-level ideas: 1. Store a vector of critical points: - We do so by keep track of node before ("parent") and node after the current node we are at, as well as “index”. - Every time we move forward by a node in the iteration, we update current pointer (“head”), value of previous node (“parent”). - Stop iteration when next node is n...
Leetcode 2181 - Merge Nodes in Between Zeros [4/7/24]
Просмотров 43 месяца назад
Time Taken: ~15 mins Tag: LeetCode Medium Concept: Linked List, Array High-level ideas: - Get a vector of the values that should be in linked list in the final answer. - E.g. for [0,1,0,3,0,2,2,0], the vector should be [1,3,4]. - Construct a linked list from scratch using these values.
Leetcode 1509 - Minimum Difference Between Largest and Smallest Value in Three Moves [3/7/24]
Просмотров 73 месяца назад
Time Taken: ~15 mins Tag: LeetCode Medium Concept: Sorting, Greedy High-level ideas: - Base case: - Since we can at most change 3 moves, if nums.size() less than or equal to 3, return 0. Because we can change all numbers to the same value. - Else: - It makes sense to want to change numbers that are smallest or largest as to make an effective change to the "minimum diff between largest and small...
Leetcode 350 - Intersection of Two Arrays II [2/7/24]
Просмотров 23 месяца назад
Time Taken: ~5 mins Tag: LeetCode Easy Concept: Counting Sort High-level ideas: - Since range of value of nums is from 0 to 1000 inclusive only, we can use counting sort. - Keep track of 2 arrays (“freq1”, “freq2”) of length 1001 for “nums1” and “nums2” respectively and store information of the frequency of occurrence of index. - e.g. freq1[0] contains frequency of occurrence of 0 in “nums1”. -...
Leetcode 1550 - Three Consecutive Odds [1/7/24]
Просмотров 43 месяца назад
Time Taken: ~5 mins Tag: LeetCode Easy Concept: Sliding Window High-level ideas: - Keep track of “startInd” and “endInd” of current effective sliding window of consecutive odd numbers - If size of window 3, return true
Leetcode 1579 - Remove Max Number of Edges to Keep Graph Fully Traversable [30/6/24]
Просмотров 53 месяца назад
Time Taken: More than 1hr Tag: LeetCode Hard Concept: ufds/Disjoint Set Basic ideas: - Keep a ufds for Alice and Bob respectively. The purpose of disjoint set is to keep track of the nodes that are connected (can reach each other starting from any node). - Iterate through edges vector. Since type 3 edges cover both Alice and Bob, we want to greedily consider these edges over type 1 or type 2 ed...
Leetcode 2192 - All Ancestors of a Node in a Directed Acyclic Graph [29/6/24]
Просмотров 123 месяца назад
Time Taken: ~45 mins Tag: LeetCode Medium Basic ideas: - Observation: By reversing all edges of graph, we can find all ancestors from a node by doing dfs or bfs from that node. Whichever node that can be reached would have been the ancestor of the node, for the original graph. High-level Steps: 1. Reverse edges of graph 2. Traverse through reversed graph and do dfs/bfs for each node. Add unique...
Leetcode 2285 - Maximum Total Importance of Roads [28/6/24]
Просмотров 33 месяца назад
Time Taken: ~5 mins Tag: LeetCode Medium Basic ideas: - Get frequency of each node appearing - Sort frequency in ascending order - Iterate through frequency vector and assign importance in ascending order starting from 1. Accumulate to ans to calculate the total maximal importance.
Leetcode 1791 - Find Center of Star Graph [27/6/24]
Просмотров 23 месяца назад
Leetcode 1791 - Find Center of Star Graph [27/6/24]
Leetcode 1382 - Balance a Binary Search Tree [26/6/24]
Просмотров 33 месяца назад
Leetcode 1382 - Balance a Binary Search Tree [26/6/24]
Leetcode 1038 - Binary Search Tree to Greater Sum Tree [25/6/24]
Просмотров 23 месяца назад
Leetcode 1038 - Binary Search Tree to Greater Sum Tree [25/6/24]
Leetcode 995 - Minimum Number of K Consecutive Bit Flips [24/6/24]
Просмотров 63 месяца назад
Leetcode 995 - Minimum Number of K Consecutive Bit Flips [24/6/24]
Leetcode 1438 - Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit [23/6/24]
Просмотров 173 месяца назад
Leetcode 1438 - Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit [23/6/24]
Leetcode 1248 - Count Number of Nice Subarrays [22/6/24]
Просмотров 43 месяца назад
Leetcode 1248 - Count Number of Nice Subarrays [22/6/24]
Leetcode 1052 - Grumpy Bookstore Owner [21/6/24]
Просмотров 73 месяца назад
Leetcode 1052 - Grumpy Bookstore Owner [21/6/24]
Leetcode 1552 - Magnetic Force Between Two Balls [20/6/24]
Просмотров 73 месяца назад
Leetcode 1552 - Magnetic Force Between Two Balls [20/6/24]
Leetcode 1482 - Minimum Number of Days to Make m Bouquets [19/6/24]
Просмотров 43 месяца назад
Leetcode 1482 - Minimum Number of Days to Make m Bouquets [19/6/24]
Leetcode 826 - Most Profit Assigning Work [18/6/24]
Просмотров 63 месяца назад
Leetcode 826 - Most Profit Assigning Work [18/6/24]
Leetcode 633 - Sum of Square Numbers [17/6/24]
Просмотров 23 месяца назад
Leetcode 633 - Sum of Square Numbers [17/6/24]
Leetcode 330 - Patching Array [16/6/24]
Просмотров 93 месяца назад
Leetcode 330 - Patching Array [16/6/24]
Leetcode 502 - IPO [15/6/24]
Просмотров 23 месяца назад
Leetcode 502 - IPO [15/6/24]
Leetcode 945 - Minimum Increment to Make Array Unique [14/6/24]
Просмотров 74 месяца назад
Leetcode 945 - Minimum Increment to Make Array Unique [14/6/24]
Leetcode 2037 - Minimum Number of Moves to Seat Everyone [13/6/24]
Просмотров 64 месяца назад
Leetcode 2037 - Minimum Number of Moves to Seat Everyone [13/6/24]