Middle of the Linked List Given the first node in a linked list, get the node which represents the middle of the list. If there are two middle nodes, ie when there is an even number of nodes, return the second node. To solve this, you use two iterators: one which moves +1 each iteration and another which moves +2. f(x) = x + 1, g(x) = x + 2....
read more

Oct 2022

Break a Palindrome Question states that given a palindrome, create the next lexicographical string that turns it no longer into a palindrome. Ex. abccba aaccba To solve this, you convert the next letter which is not an ‘a’ to an ‘a’ so that it becomes the next string. This will always be the next lexicographical string. For the case where all the letters are ‘a’ aaaaaaaa aaaaaaab You want the...
read more

Oct 2022

My Calender III Question states to create a class called my calendar III which has a function which adds bookings to the calendar. When you add a booking with a start and end time, which are integers, you have to return the max number of intersections between the bookings for the calender. Ex. Let’s say the bookings are as follows: [10, 20] [15, 30] [40, 50] [3, 18] The first...
read more

Oct 2022

Two Sum Attempt to recall: Question is “Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.” Intersection of Two Arrays vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { vector<int> ans; vector<int>::iterator it; for(int i = 0; i < nums1.size(); i++){ it = find(nums2.begin(),nums2.end(),nums1[i]); if( it != nums2.end() ){ ans.push_back(nums1[i]); *it = -1; } } return ans; } vector<int>...
read more

Nov 2021

Okay, so I tried to take notes but it was so boring. I’d rather do questions. There’s this thing called study plan on leetcode which I’m prolly just gonna follow. I clicked on all three study plans: algorithms and dynamic programming (DP). And lemme just say I kinda struggled with the two already for data structures. I started at around 12:30 PM and now it’s 2:06 PM. Contains Duplicate The...
read more

Nov 2021

i def did not skip a day Question 1: First Bad Version Today I got to solve a problem called first bad version. What you essentially do is try to find which is the bad version given that a function tells you whether or not it is a bad version. All versions after a bad version become bad. For example FFTTTTTTT, The index at 2 or the 3rd item is...
read more

Nov 2021

Okay, so I’m premed who likes to code, so I’m just gonna start now. I did a question yesterday on binary search and I will attempt to answer it again right now. Binary Search def binary_search(nums, target): left = 0 right = len(nums) - 1 while(left < right): mid = int((left+right)/2) if( nums[mid] < target ): left = mid + 1 elif( nums[mid] > target ): right = mid -...
read more

Nov 2021
Popular
Years