Name: Integer to RomanDifficulty: MediumDescription: Convert an integer to Roman Numerals Example: Input: num = 3 Output: “III Input: num = 58 Output: “LVIII” Input: num = 1994 Output: “MCMXCIV” Just used a simple approach for this one, it’s self-explanatory.
Name: Remove Nth Node From End of ListDifficulty: MediumDescription: Remove the nth node from the end of the list, return the list Example: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Input: head = , n = 1 Output:  Input: head = [1,2], n = 1 Output:  Tried to do this in […]
Name: String to Integer (atoi)Difficulty: MediumDescription: Convert a string to an integer as per the C++ atoi function Example: Input: s = “42” Output: 42 Input: s = ” -42″ Output: -42 Input: s = “4193 with words” Output: 4193 This is a pretty straight forward solution, I enjoy writing code that parses text.
Name: Reverse IntegerDifficulty: MediumDescription: Reverse the given integer, maintain the negative sign Example: Input: x = 123 Output: 321 Input: x = -123 Output: -321 Input: x = 120 Output: 21 This was quite easy, except for overflows. You have to check the number never exceeds an integer. Other than that, it’s a matter of […]
Name: Add Two NumbersDifficulty: MediumDescription: Add two numbers stored in reverse in a linked list Example: Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807. Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9] Output: [8,9,9,9,0,0,0,1] Initially when solving this problem, I first made sure the lists were the same size […]
Name: Add BinaryDifficulty: EasyDescription: Given two binary strings a and b, return their sum as a binary string. Example: Input: a = “1010”, b = “1011” Output: “10101” This one stretched the memory. We add bits from right to left, bit by bit, so the first thing we need to do is reverse the string […]
Name: Plus OneDifficulty: EasyDescription: Increment the large integer by one and return the resulting array of digits. Example: Input: digits = [4,3,2,1] Output: [4,3,2,2] Explanation: The array represents the integer 4321. Incrementing by one gives 4321 + 1 = 4322. Thus, the result should be [4,3,2,2]. Feels like I hacked this one, I also modified […]
Name: Length of Last WordDifficulty: EasyDescription: Find the length of the last word Example: Input: s = ” fly me to the moon ” Output: 4 Explanation: The last word is “moon” with length 4.
Name: Maximum SubarrayDifficulty: EasyDescription: Find the value of the largest contiguous subarray. Example: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. This one, although simple, tripped me up. I was using Brute Force but it was too slow. I kept getting timeouts. Some of the tests use arrays with […]
Name: Search Insert PositionDifficulty: EasyDescription: Return the index of target, or where target should be in a sorted array Example: Input: nums = [1,3,5,6], target = 5 Output: 2 Input: nums = [1,3,5,6], target = 2 Output: 1 Input: nums = [1,3,5,6], target = 7 Output: 4 The solution was quite simple, but I complicated […]